void xfdashboard_text_box_set_text(XfdashboardTextBox *self, const gchar *inMarkupText) { XfdashboardTextBoxPrivate *priv; const gchar *text; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); priv=self->priv; /* Set value if changed */ if(g_strcmp0(clutter_text_get_text(CLUTTER_TEXT(priv->actorTextBox)), inMarkupText)!=0) { clutter_text_set_markup(CLUTTER_TEXT(priv->actorTextBox), inMarkupText); text=clutter_text_get_text(CLUTTER_TEXT(priv->actorTextBox)); if((text==NULL || *text==0) && priv->isEditable) { clutter_actor_show(priv->actorHintLabel); } else { clutter_actor_hide(priv->actorHintLabel); } clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_TEXT]); } }
/* Virtual function "can_focus" was called */ static gboolean _xfdashboard_text_box_focusable_can_focus(XfdashboardFocusable *inFocusable) { XfdashboardTextBox *self; XfdashboardTextBoxPrivate *priv; XfdashboardFocusableInterface *selfIface; XfdashboardFocusableInterface *parentIface; g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(inFocusable), CLUTTER_EVENT_PROPAGATE); self=XFDASHBOARD_TEXT_BOX(inFocusable); priv=self->priv; /* Check if actor could be focused at all ... */ selfIface=XFDASHBOARD_FOCUSABLE_GET_IFACE(inFocusable); parentIface=g_type_interface_peek_parent(selfIface); if(parentIface && parentIface->can_focus) { if(!parentIface->can_focus(inFocusable)) return(FALSE); } /* ... then only an editable text box can be focused */ if(priv->isEditable) return(TRUE); /* If we get here this actor cannot be focused */ return(FALSE); }
/* 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)); }
/* Secondary icon was clicked */ static void _xfdashboard_text_box_on_secondary_icon_clicked(XfdashboardTextBox *self, gpointer inUserData) { g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); /* Emit signal for clicking secondary icon */ g_signal_emit(self, XfdashboardTextBoxSignals[SIGNAL_SECONDARY_ICON_CLICKED], 0); }
/* Get/set text of editable text box */ gboolean xfdashboard_text_box_is_empty(XfdashboardTextBox *self) { const gchar *text; g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), TRUE); text=clutter_text_get_text(CLUTTER_TEXT(self->priv->actorTextBox)); return(text==NULL || *text==0); }
gint xfdashboard_text_box_get_length(XfdashboardTextBox *self) { const gchar *text; gint textLength=0; g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), 0); text=clutter_text_get_text(CLUTTER_TEXT(self->priv->actorTextBox)); if(text) textLength=strlen(text); return(textLength); }
void xfdashboard_text_box_set_hint_text_va(XfdashboardTextBox *self, const gchar *inFormat, ...) { gchar *text; va_list args; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); /* Build formatted text to set */ va_start(args, inFormat); text=g_strdup_vprintf(inFormat, args); va_end(args); /* Set formatted text */ xfdashboard_text_box_set_hint_text(self, text); /* Release allocated resources */ g_free(text); }
void xfdashboard_text_box_set_spacing(XfdashboardTextBox *self, gfloat inSpacing) { XfdashboardTextBoxPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); g_return_if_fail(inSpacing>=0.0f); priv=self->priv; /* Set value if changed */ if(priv->spacing!=inSpacing) { priv->spacing=inSpacing; clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_SPACING]); } }
void xfdashboard_text_box_set_secondary_icon(XfdashboardTextBox *self, const gchar *inIconName) { XfdashboardTextBoxPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); g_return_if_fail(!inIconName || strlen(inIconName)>0); priv=self->priv; /* Set themed icon name or icon file name for primary icon */ if(g_strcmp0(priv->secondaryIconName, inIconName)!=0) { /* Set new primary icon name */ if(priv->secondaryIconName) { g_free(priv->secondaryIconName); priv->secondaryIconName=NULL; } if(inIconName) { /* Load and set new icon */ priv->secondaryIconName=g_strdup(inIconName); xfdashboard_button_set_icon(XFDASHBOARD_BUTTON(priv->actorSecondaryIcon), priv->secondaryIconName); /* Show icon */ priv->showSecondaryIcon=TRUE; clutter_actor_show(priv->actorSecondaryIcon); clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); } else { /* Hide icon */ priv->showSecondaryIcon=FALSE; clutter_actor_hide(priv->actorSecondaryIcon); clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); } /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_SECONDARY_ICON_NAME]); } }
void xfdashboard_text_box_set_hint_text_font(XfdashboardTextBox *self, const gchar *inFont) { XfdashboardTextBoxPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); priv=self->priv; /* Set value if changed */ if(g_strcmp0(priv->hintTextFont, inFont)!=0) { if(priv->hintTextFont) g_free(priv->hintTextFont); priv->hintTextFont=g_strdup(inFont); clutter_text_set_font_name(CLUTTER_TEXT(priv->actorHintLabel), priv->hintTextFont); clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_HINT_TEXT_FONT]); } }
void xfdashboard_text_box_set_hint_text(XfdashboardTextBox *self, const gchar *inMarkupText) { XfdashboardTextBoxPrivate *priv; gboolean newHintTextSet; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); priv=self->priv; newHintTextSet=FALSE; /* Freeze notification */ g_object_freeze_notify(G_OBJECT(self)); /* Set value if changed */ if(g_strcmp0(clutter_text_get_text(CLUTTER_TEXT(priv->actorHintLabel)), inMarkupText)!=0) { /* Set value */ clutter_text_set_markup(CLUTTER_TEXT(priv->actorHintLabel), inMarkupText); clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_HINT_TEXT]); } /* Check if a hint text was set and if read-only property changes. * Note: NULL string will unset "hint-text-set" property (set to FALSE) */ if(inMarkupText) newHintTextSet=TRUE; if(newHintTextSet!=priv->hintTextSet) { /* Set flag */ priv->hintTextSet=newHintTextSet; /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_HINT_TEXT_SET]); } /* Thaw notification */ g_object_thaw_notify(G_OBJECT(self)); }
void xfdashboard_text_box_set_hint_text_color(XfdashboardTextBox *self, const ClutterColor *inColor) { XfdashboardTextBoxPrivate *priv; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); g_return_if_fail(inColor); priv=self->priv; /* Set value if changed */ if(!priv->hintTextColor || !clutter_color_equal(inColor, priv->hintTextColor)) { if(priv->hintTextColor) clutter_color_free(priv->hintTextColor); priv->hintTextColor=clutter_color_copy(inColor); clutter_text_set_color(CLUTTER_TEXT(priv->actorHintLabel), priv->hintTextColor); clutter_actor_queue_redraw(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_HINT_TEXT_COLOR]); } }
/* Virtual function "handle_key_event" was called */ static gboolean _xfdashboard_text_box_focusable_handle_key_event(XfdashboardFocusable *inFocusable, const ClutterEvent *inEvent) { XfdashboardTextBox *self; XfdashboardTextBoxPrivate *priv; gboolean result; g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(inFocusable), CLUTTER_EVENT_PROPAGATE); self=XFDASHBOARD_TEXT_BOX(inFocusable); priv=self->priv; result=CLUTTER_EVENT_PROPAGATE; /* Push event to real text box if available */ if(priv->actorTextBox) { result=clutter_actor_event(priv->actorTextBox, inEvent, FALSE); } /* Return event handling result */ return(result); }
void xfdashboard_text_box_set_text_color(XfdashboardTextBox *self, const ClutterColor *inColor) { XfdashboardTextBoxPrivate *priv; ClutterColor selectionColor; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); g_return_if_fail(inColor); priv=self->priv; /* Set value if changed */ if(!priv->textColor || !clutter_color_equal(inColor, priv->textColor)) { if(priv->textColor) clutter_color_free(priv->textColor); priv->textColor=clutter_color_copy(inColor); clutter_text_set_color(CLUTTER_TEXT(priv->actorTextBox), priv->textColor); /* Selection text and background color is inverted text color if not set */ if(!priv->selectionColorSet) { selectionColor.red=0xff-priv->textColor->red; selectionColor.green=0xff-priv->textColor->green; selectionColor.blue=0xff-priv->textColor->blue; selectionColor.alpha=priv->textColor->alpha; clutter_text_set_selected_text_color(CLUTTER_TEXT(priv->actorTextBox), &selectionColor); /* Selection color is the same as text color */ clutter_text_set_selection_color(CLUTTER_TEXT(priv->actorTextBox), priv->textColor); } /* Redraw actor in new color */ clutter_actor_queue_redraw(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_TEXT_COLOR]); } }
/* A key was released */ static gboolean _xfdashboard_text_box_on_key_release_event(ClutterActor *inActor, ClutterEvent *inEvent, gpointer inUserData) { XfdashboardTextBox *self; XfdashboardTextBoxPrivate *priv; gboolean result; g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(inActor), CLUTTER_EVENT_PROPAGATE); self=XFDASHBOARD_TEXT_BOX(inActor); priv=self->priv; result=CLUTTER_EVENT_PROPAGATE; /* Push event to real text box if available */ if(priv->actorTextBox) { result=clutter_actor_event(priv->actorTextBox, inEvent, FALSE); } /* Return event handling result */ return(result); }
/* Text of editable text box has changed */ static void _xfdashboard_text_box_on_text_changed(XfdashboardTextBox *self, gpointer inUserData) { XfdashboardTextBoxPrivate *priv; ClutterText *actorText; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); g_return_if_fail(CLUTTER_IS_TEXT(inUserData)); priv=self->priv; actorText=CLUTTER_TEXT(inUserData); /* Show hint label depending if text box is empty or not */ if(xfdashboard_text_box_is_empty(self) && priv->isEditable) { clutter_actor_show(priv->actorHintLabel); } else { clutter_actor_hide(priv->actorHintLabel); } /* Emit signal for text changed */ g_signal_emit(self, XfdashboardTextBoxSignals[SIGNAL_TEXT_CHANGED], 0, clutter_text_get_text(actorText)); }
void xfdashboard_text_box_set_editable(XfdashboardTextBox *self, gboolean isEditable) { XfdashboardTextBoxPrivate *priv; const gchar *text; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); priv=self->priv; /* Set value if changed */ if(priv->isEditable!=isEditable) { priv->isEditable=isEditable; if(priv->isEditable) xfdashboard_stylable_add_pseudo_class(XFDASHBOARD_STYLABLE(self), "editable"); else xfdashboard_stylable_remove_pseudo_class(XFDASHBOARD_STYLABLE(self), "editable"); /* Set up actors */ clutter_text_set_selectable(CLUTTER_TEXT(priv->actorTextBox), priv->isEditable); clutter_text_set_editable(CLUTTER_TEXT(priv->actorTextBox), priv->isEditable); text=clutter_text_get_text(CLUTTER_TEXT(priv->actorTextBox)); if((text==NULL || *text==0) && priv->isEditable) { clutter_actor_show(priv->actorHintLabel); } else { clutter_actor_hide(priv->actorHintLabel); } clutter_actor_queue_relayout(CLUTTER_ACTOR(self)); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_EDITABLE]); } }
/* Get/set text of hint label */ const gchar* xfdashboard_text_box_get_hint_text(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), NULL); return(clutter_text_get_text(CLUTTER_TEXT(self->priv->actorHintLabel))); }
/* Get/set flag to mark text editable */ gboolean xfdashboard_text_box_get_editable(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), FALSE); return(self->priv->isEditable); }
/* Get/set secondary icon */ const gchar* xfdashboard_text_box_get_secondary_icon(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), NULL); return(self->priv->secondaryIconName); }
/* Get/set color of background of selected text */ const ClutterColor* xfdashboard_text_box_get_selection_background_color(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), NULL); return(self->priv->selectionBackgroundColor); }
void xfdashboard_text_box_set_selection_background_color(XfdashboardTextBox *self, const ClutterColor *inColor) { XfdashboardTextBoxPrivate *priv; ClutterColor selectionColor; g_return_if_fail(XFDASHBOARD_IS_TEXT_BOX(self)); priv=self->priv; /* Set value if changed */ if(priv->selectionBackgroundColor!=inColor || (priv->selectionBackgroundColor && inColor && !clutter_color_equal(inColor, priv->selectionBackgroundColor))) { /* Freeze notifications and collect them */ g_object_freeze_notify(G_OBJECT(self)); /* Release old color */ if(priv->selectionBackgroundColor) { clutter_color_free(priv->selectionBackgroundColor); priv->selectionBackgroundColor=NULL; /* Check if any selection color is set */ priv->selectionColorSet=((priv->selectionTextColor && priv->selectionBackgroundColor) ? TRUE : FALSE); /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_SELECTION_BACKGROUND_COLOR]); } /* Set new color if available */ if(inColor) { priv->selectionBackgroundColor=clutter_color_copy(inColor); clutter_text_set_selection_color(CLUTTER_TEXT(priv->actorTextBox), priv->selectionBackgroundColor); /* Any selection color was set */ priv->selectionColorSet=TRUE; /* Notify about property change */ g_object_notify_by_pspec(G_OBJECT(self), XfdashboardTextBoxProperties[PROP_SELECTION_BACKGROUND_COLOR]); } /* Selection text and background color is inverted text color if not set */ if(!priv->selectionColorSet) { selectionColor.red=0xff-priv->textColor->red; selectionColor.green=0xff-priv->textColor->green; selectionColor.blue=0xff-priv->textColor->blue; selectionColor.alpha=priv->textColor->alpha; clutter_text_set_selected_text_color(CLUTTER_TEXT(priv->actorTextBox), &selectionColor); /* Selection color is the same as text color */ clutter_text_set_selection_color(CLUTTER_TEXT(priv->actorTextBox), priv->textColor); } /* Redraw actor in new color */ clutter_actor_queue_redraw(CLUTTER_ACTOR(self)); /* Thaw notifications and send them now */ g_object_thaw_notify(G_OBJECT(self)); } }
/* Get/set color of text in hint label */ const ClutterColor* xfdashboard_text_box_get_hint_text_color(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), NULL); return(self->priv->hintTextColor); }
/* Determine if a hint label was set */ gboolean xfdashboard_text_box_is_hint_text_set(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), FALSE); return(self->priv->hintTextSet); }
/* Get/set font of hint label */ const gchar* xfdashboard_text_box_get_hint_text_font(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), NULL); return(self->priv->hintTextFont); }
/* Get/set spacing between text and icon actors */ gfloat xfdashboard_text_box_get_spacing(XfdashboardTextBox *self) { g_return_val_if_fail(XFDASHBOARD_IS_TEXT_BOX(self), 0); return(self->priv->spacing); }