* @ingroup Elementary
*
* This is a editfield. It can contain a simple label and icon objects.
+ *
+ * Smart callbacks that you can add are:
+ *
+ * clicked - This signal is emitted when an editfield is clicked.
+ *
+ * unfocused - This signal is emitted when an editfield is unfocused.
+ *
*/
//#define ERASER_PADDING (10)
{
Evas_Object *base;
Evas_Object *entry;
+ Evas_Object *scroller;
Evas_Object *ricon;
Evas_Object *licon;
const char *label;
Eina_Bool show_guide_text:1;
Eina_Bool editing:1;
Eina_Bool single_line:1;
+ Eina_Bool eraser_show:1;
};
static const char *widtype = NULL;
_on_focus_hook(void *data, Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
- const char* text;
if (!wd || !wd->base)
- return ;
+ return;
if (!elm_widget_focus_get(obj) && !(elm_widget_disabled_get(obj)) )
{
- wd->editing = EINA_FALSE;
- edje_object_signal_emit(wd->base, "elm,state,over,show", "elm");
- if(_empty_entry(wd->entry))
- {
- if(wd->guide_text)
- {
- edje_object_part_text_set(wd->base, "elm.guidetext", wd->guide_text);
- edje_object_signal_emit(wd->base, "elm,state,guidetext,visible", "elm");
- wd->show_guide_text = EINA_TRUE;
- }
- }
+ evas_object_smart_callback_call(obj, "unfocused", NULL);
+ wd->editing = EINA_FALSE;
+ edje_object_signal_emit(wd->base, "elm,state,over,show", "elm");
+ edje_object_signal_emit(wd->base, "elm,state,eraser,hidden", "elm");
+ if(_empty_entry(wd->entry))
+ {
+ if(wd->guide_text)
+ {
+ edje_object_part_text_set(wd->base, "elm.guidetext", wd->guide_text);
+ edje_object_signal_emit(wd->base, "elm,state,guidetext,visible", "elm");
+ wd->show_guide_text = EINA_TRUE;
+ }
+ }
}
}
{
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd || !wd->base)
- return;
+ return;
_elm_theme_object_set(obj, wd->base, "editfield", "base", elm_widget_style_get(obj));
- edje_object_part_swallow(wd->base, "elm.swallow.content", wd->entry);
+ if(wd->single_line)
+ edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scroller);
+ else
+ edje_object_part_swallow(wd->base, "elm.swallow.content", wd->entry);
if(!wd->editing)
- edje_object_signal_emit(wd->base, "elm,state,over,show", "elm");
+ edje_object_signal_emit(wd->base, "elm,state,over,show", "elm");
if(wd->show_guide_text)
{
- if(_empty_entry(wd->entry))
- {
- if(wd->guide_text)
- {
- edje_object_part_text_set(wd->base, "elm.guidetext", wd->guide_text);
- edje_object_signal_emit(wd->base, "elm,state,guidetext,visible", "elm");
- }
- }
+ if(_empty_entry(wd->entry))
+ {
+ if(wd->guide_text)
+ {
+ edje_object_part_text_set(wd->base, "elm.guidetext", wd->guide_text);
+ edje_object_signal_emit(wd->base, "elm,state,guidetext,visible", "elm");
+ }
+ }
}
if(wd->ricon)
- edje_object_part_swallow(wd->base, "right_icon", wd->ricon);
+ edje_object_part_swallow(wd->base, "right_icon", wd->ricon);
if(wd->licon)
- edje_object_part_swallow(wd->base, "left_icon", wd->licon);
+ edje_object_part_swallow(wd->base, "left_icon", wd->licon);
_sizing_eval(obj);
}
Widget_Data *wd = elm_widget_data_get(obj);
if (wd->needs_size_calc)
{
- _sizing_eval(obj);
- wd->needs_size_calc = EINA_FALSE;
+ _sizing_eval(obj);
+ wd->needs_size_calc = EINA_FALSE;
}
}
static void
_sizing_eval(Evas_Object *obj)
{
- Widget_Data *wd = elm_widget_data_get(obj);
- Evas_Coord minw = -1, minh = -1;
- edje_object_size_min_calc(wd->base, &minw, &minh);
- evas_object_size_hint_min_set(obj, minw, minh);
- evas_object_size_hint_max_set(obj, -1, -1);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ Evas_Coord minw = -1, minh = -1;
+ edje_object_size_min_calc(wd->base, &minw, &minh);
+ evas_object_size_hint_min_set(obj, minw, minh);
+ evas_object_size_hint_max_set(obj, -1, -1);
}
static void
{
Widget_Data *wd = elm_widget_data_get(obj);
if(!wd || !wd->base)
- return;
+ return;
if (wd->needs_size_calc)
- return;
+ return;
wd->needs_size_calc = EINA_TRUE;
evas_object_smart_changed(obj);
}
double weight_x;
evas_object_size_hint_weight_get(data, &weight_x, NULL);
if (weight_x == EVAS_HINT_EXPAND)
- _request_sizing_eval(data);
+ _request_sizing_eval(data);
}
static Eina_Bool
if(!text) return EINA_FALSE;
strip_text = elm_entry_markup_to_utf8(text);
if (strip_text) {
- len = strlen(strip_text);
- free(strip_text);
+ len = strlen(strip_text);
+ free(strip_text);
}
if(len == 0)
- return EINA_TRUE;
+ return EINA_TRUE;
else
- return EINA_FALSE;
+ return EINA_FALSE;
}
static void
_entry_changed_cb(void *data, Evas_Object *obj, void* event_info)
{
- const char *text;
Evas_Object *ef_obj = (Evas_Object *)data;
Widget_Data *wd = elm_widget_data_get(ef_obj);
if(!_empty_entry(wd->entry))
{
+ if(wd->eraser_show && elm_object_focus_get(obj))
+ edje_object_signal_emit(wd->base, "elm,state,eraser,show", "elm");
if(wd->guide_text)
{
edje_object_signal_emit(wd->base, "elm,state,guidetext,hidden", "elm");
wd->show_guide_text = EINA_FALSE;
}
}
+ else
+ {
+ if(wd->eraser_show)
+ edje_object_signal_emit(wd->base, "elm,state,eraser,hidden", "elm");
+ }
}
static void
if(!strcmp(source, "eraser"))
{
- elm_entry_entry_set(wd->entry, "");
+ elm_entry_entry_set(wd->entry, "");
+ edje_object_signal_emit(wd->base, "elm,state,eraser,hidden", "elm");
}
else if(strcmp(source, "left_icon") && strcmp(source, "right_icon") && strcmp(source, "eraser"))
{
- edje_object_signal_emit(wd->base, "elm,state,over,hide", "elm");
- elm_widget_focus_set(wd->entry, EINA_TRUE);
-
- if(wd->editing == EINA_FALSE)
- elm_entry_cursor_end_set(wd->entry);
-
- if(wd->guide_text)
- {
- edje_object_signal_emit(wd->base, "elm,state,guidetext,hidden", "elm");
- wd->show_guide_text = EINA_FALSE;
- }
- evas_object_smart_callback_call(data, "clicked", NULL);
- wd->editing = EINA_TRUE;
+ edje_object_signal_emit(wd->base, "elm,state,over,hide", "elm");
+
+ elm_object_focus(wd->entry);
+
+ if(wd->editing == EINA_FALSE)
+ elm_entry_cursor_end_set(wd->entry);
+
+ if(!(_empty_entry(wd->entry)) && (wd->eraser_show))
+ edje_object_signal_emit(wd->base, "elm,state,eraser,show", "elm");
+
+ if(wd->guide_text)
+ {
+ edje_object_signal_emit(wd->base, "elm,state,guidetext,hidden", "elm");
+ wd->show_guide_text = EINA_FALSE;
+ }
+ evas_object_smart_callback_call(data, "clicked", NULL);
+ wd->editing = EINA_TRUE;
}
}
_resize_cb(void *data, Evas *evas, Evas_Object *obj, void *event)
{
Widget_Data *wd = elm_widget_data_get(data);
- Evas_Coord w, h;
+ Evas_Coord h;
if (!wd || !wd->base) return;
evas_object_geometry_get(obj, NULL, NULL, NULL, &h);
}
+static void
+_signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+ edje_object_signal_emit(wd->base, emission, source);
+}
+
+
/**
* Add a new editfield object
*
Evas *e;
Widget_Data *wd;
- wd = ELM_NEW(Widget_Data);
e = evas_object_evas_get(parent);
if (e == NULL)
- return NULL;
+ return NULL;
+ wd = ELM_NEW(Widget_Data);
obj = elm_widget_add(e);
ELM_SET_WIDTYPE(widtype, "editfield");
elm_widget_type_set(obj, "editfield");
elm_widget_theme_hook_set(obj, _theme_hook);
elm_widget_changed_hook_set(obj, _changed_hook);
elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
+ elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
elm_widget_can_focus_set(obj, EINA_TRUE);
wd->base = edje_object_add(e);
_elm_theme_object_set(obj, wd->base, "editfield", "base", "default");
elm_widget_resize_object_set(obj, wd->base);
edje_object_signal_callback_add(wd->base, "mouse,clicked,1", "*",
- _signal_mouse_clicked, obj);
+ _signal_mouse_clicked, obj);
+ edje_object_signal_callback_add(wd->base, "clicked", "*",
+ _signal_mouse_clicked, obj);
+
evas_object_event_callback_add(wd->base, EVAS_CALLBACK_RESIZE, _resize_cb, obj);
wd->editing = EINA_FALSE;
wd->single_line = EINA_FALSE;
+ wd->eraser_show = EINA_TRUE;
wd->entry = elm_entry_add(obj);
elm_object_style_set(wd->entry, "editfield");
evas_object_size_hint_weight_set(wd->entry, 0, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(wd->entry, 0, EVAS_HINT_FILL);
evas_object_event_callback_add(wd->entry,
- EVAS_CALLBACK_CHANGED_SIZE_HINTS,
- _changed_size_hints, obj);
+ EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+ _changed_size_hints, obj);
edje_object_part_swallow(wd->base, "elm.swallow.content", wd->entry);
evas_object_smart_callback_add(wd->entry, "changed", _entry_changed_cb, obj);
elm_widget_sub_object_add(obj, wd->entry);
-
_sizing_eval(obj);
return obj;
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype);
if (!wd || !wd->base)
- return;
+ return;
if (wd->label)
- eina_stringshare_del(wd->label);
+ eina_stringshare_del(wd->label);
if (label)
{
- wd->label = eina_stringshare_add(label);
- edje_object_signal_emit(wd->base, "elm,state,text,visible", "elm");
- edje_object_signal_emit(wd->base, "elm,state,left,icon,hide", "elm");
+ wd->label = eina_stringshare_add(label);
+ edje_object_signal_emit(wd->base, "elm,state,text,visible", "elm");
+ edje_object_signal_emit(wd->base, "elm,state,left,icon,hide", "elm");
}
else
{
- wd->label = NULL;
- edje_object_signal_emit(wd->base, "elm,state,text,hidden", "elm");
- edje_object_signal_emit(wd->base, "elm,state,left,icon,show", "elm");
+ wd->label = NULL;
+ edje_object_signal_emit(wd->base, "elm,state,text,hidden", "elm");
+ edje_object_signal_emit(wd->base, "elm,state,left,icon,show", "elm");
}
edje_object_message_signal_process(wd->base);
edje_object_part_text_set(wd->base, "elm.text", label);
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
if (!wd || !wd->base)
- return NULL;
- return wd->label;
+ return NULL;
+ return wd->label;
}
/**
- * Get the label used on the editfield object
+ * Set the guidance text used on the editfield object
*
* @param obj The editfield object
* @return label text
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype);
if (!wd || !wd->base)
- return;
+ return;
if (wd->guide_text)
- eina_stringshare_del(wd->guide_text);
+ eina_stringshare_del(wd->guide_text);
if (text)
{
- wd->guide_text = eina_stringshare_add(text);
- edje_object_part_text_set(wd->base, "elm.guidetext", wd->guide_text);
- wd->show_guide_text = EINA_TRUE;
+ wd->guide_text = eina_stringshare_add(text);
+ edje_object_part_text_set(wd->base, "elm.guidetext", wd->guide_text);
+ wd->show_guide_text = EINA_TRUE;
}
else
- wd->guide_text = NULL;
+ wd->guide_text = NULL;
}
/**
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
if (!wd || !wd->base)
- return NULL;
+ return NULL;
return wd->guide_text;
}
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
if (!wd)
- return NULL;
+ return NULL;
return wd->entry;
}
*
* @param obj The editfield object
* @param icon The icon object
- * @return 1 if setting is done, 0 if there is no swallow part for the icon.
*
* @ingroup Editfield
*/
-EAPI Eina_Bool
+EAPI void
elm_editfield_left_icon_set(Evas_Object *obj, Evas_Object *icon)
{
Widget_Data *wd = elm_widget_data_get(obj);
- ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
- if (!wd || !wd->base)
- return EINA_FALSE;
+ ELM_CHECK_WIDTYPE(obj, widtype) ;
+ if (!wd || !wd->base || !icon)
+ return;
if ((wd->licon != icon) && (wd->licon))
- elm_widget_sub_object_del(obj, wd->licon);
+ elm_widget_sub_object_del(obj, wd->licon);
if (icon)
{
- if (!(edje_object_part_swallow(wd->base, "left_icon", icon)))
- return EINA_FALSE;
- wd->licon = icon;
- elm_widget_sub_object_add(obj, icon);
- evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
- _changed_size_hints, obj);
- edje_object_signal_emit(wd->base, "elm,state,left,icon,show", "elm");
- edje_object_signal_emit(wd->base, "elm,state,text,hidden", "elm");
- _sizing_eval(obj);
+ if (!(edje_object_part_swallow(wd->base, "left_icon", icon)))
+ return;
+ wd->licon = icon;
+ elm_widget_sub_object_add(obj, icon);
+ evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+ _changed_size_hints, obj);
+ edje_object_signal_emit(wd->base, "elm,state,left,icon,show", "elm");
+ edje_object_signal_emit(wd->base, "elm,state,text,hidden", "elm");
+ _sizing_eval(obj);
}
- return EINA_TRUE;
+ return;
}
/**
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
if (!wd || !wd->base || !wd->licon)
- return NULL;
+ return NULL;
return wd->licon;
}
*
* @param obj The editfield object
* @param icon The icon object
- * @return 1 if setting is done, 0 if there is no swallow part for the icon.
*
* @ingroup Editfield
*/
-EAPI Eina_Bool
+EAPI void
elm_editfield_right_icon_set(Evas_Object *obj, Evas_Object *icon)
{
Widget_Data *wd = elm_widget_data_get(obj);
- ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
- if (!wd || !wd->base)
- return EINA_FALSE;
+ ELM_CHECK_WIDTYPE(obj, widtype) ;
+ if (!wd || !wd->base || !icon)
+ return;
if ((wd->ricon != icon) && (wd->ricon))
- elm_widget_sub_object_del(obj, wd->ricon);
+ elm_widget_sub_object_del(obj, wd->ricon);
if (icon)
{
- if ( !(edje_object_part_swallow(wd->base, "right_icon", icon)) )
- return EINA_FALSE;
- wd->ricon = icon;
- elm_widget_sub_object_add(obj, icon);
- evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
- _changed_size_hints, obj);
- edje_object_signal_emit(wd->base, "elm,state,right,icon,show", "elm");
- _sizing_eval(obj);
+ if ( !(edje_object_part_swallow(wd->base, "right_icon", icon)) )
+ return;
+ wd->ricon = icon;
+ elm_widget_sub_object_add(obj, icon);
+ evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+ _changed_size_hints, obj);
+ edje_object_signal_emit(wd->base, "elm,state,right,icon,show", "elm");
+ _sizing_eval(obj);
}
- return EINA_TRUE;
+ return;
}
/**
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype) NULL;
if (!wd || !wd->base || !wd->ricon)
- return NULL;
+ return NULL;
return wd->ricon;
}
elm_editfield_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
{
Widget_Data *wd = elm_widget_data_get(obj);
- ELM_CHECK_WIDTYPE(obj, widtype);
- if (!wd || !wd->base)
- return;
+ Evas_Object *entry;
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ if (!wd || !wd->base || wd->single_line == single_line)
+ return;
wd->single_line = single_line;
elm_entry_single_line_set(wd->entry, single_line);
+ if(single_line)
+ {
+ if(!wd->scroller)
+ {
+ wd->scroller = elm_scroller_add(obj);
+ elm_scroller_bounce_set(wd->scroller, 0, 0);
+ elm_scroller_policy_set(wd->scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
+ elm_widget_sub_object_add(obj, wd->scroller);
+ elm_scroller_content_min_limit(wd->scroller, 0, 1);
+ }
+ edje_object_part_unswallow(wd->base, wd->entry);
+ edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scroller);
+ evas_object_size_hint_weight_set(wd->entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(wd->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+ elm_scroller_content_set(wd->scroller, wd->entry);
+ }
+ else
+ {
+ entry = elm_entry_add(obj);
+ elm_object_style_set(entry, "editfield");
+ evas_object_size_hint_weight_set(entry, 0, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(entry, 0, EVAS_HINT_FILL);
+ evas_object_event_callback_add(entry,
+ EVAS_CALLBACK_CHANGED_SIZE_HINTS,
+ _changed_size_hints, obj);
+ edje_object_part_swallow(wd->base, "elm.swallow.content", entry);
+ evas_object_smart_callback_add(entry, "changed", _entry_changed_cb, obj);
+ elm_widget_sub_object_add(obj, entry);
+ elm_entry_entry_set(entry, elm_entry_entry_get(wd->entry));
+ if(wd->scroller)
+ edje_object_part_unswallow(wd->base, wd->scroller);
+ evas_object_del(wd->entry);
+ wd->entry = entry;
+ edje_object_part_swallow(wd->base, "elm.swallow.content", wd->entry);
+ }
+}
+
+/**
+ * Get the current entry object style(single-line or multi-line)
+ *
+ * @param obj The editfield object
+ * @return 1 if single-line , 0 if multi-line
+ *
+ * @ingroup Editfield
+ */
+EAPI Eina_Bool
+elm_editfield_entry_single_line_get(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+ if (!wd || !wd->base)
+ return EINA_FALSE;
+ return wd->single_line;
}
/**
Widget_Data *wd = elm_widget_data_get(obj);
ELM_CHECK_WIDTYPE(obj, widtype);
if (!wd || !wd->base)
- return;
+ return;
+
+ wd->eraser_show = visible;
+
+ if (!visible)
+ edje_object_signal_emit(wd->base, "elm,state,eraser,hidden", "elm");
- if (visible)
- edje_object_signal_emit(wd->base, "elm,state,eraser,show", "elm");
- else
- edje_object_signal_emit(wd->base, "elm,state,eraser,hidden", "elm");
-
return;
}
+
+/**
+ * Get the current state of erase (visible/invisible)
+ *
+ * @param obj The editfield object
+ * @return 1 if visible, 0 if invisible
+ *
+ * @ingroup Editfield
+ */
+EAPI Eina_Bool
+elm_editfield_eraser_get(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+ if (!wd || !wd->base)
+ return EINA_FALSE;
+ return wd->eraser_show;
+}
+
+/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/