{
Evas_Object *base, *eb, *cancel_btn;
Eina_Bool cancel_btn_ani_flag;
+ Eina_Bool cancel_btn_show_mode;
+ Eina_Bool boundary_mode;
};
static void _del_hook(Evas_Object *obj);
static void _theme_hook(Evas_Object *obj);
+static void _on_focus_hook(void *data, Evas_Object *obj);
static void _sizing_eval(Evas_Object *obj);
-static void _clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
-static void _changed(void *data, Evas_Object *obj, const char *emission, const char *source);
-static void _cancel_clicked(void *data, Evas_Object *obj, const char *emission, const char *source);
+static void _clicked(void *data, Evas_Object *obj, void *event_info);
+static void _changed(void *data, Evas_Object *obj, void *event_info);
+static void _cancel_clicked(void *data, Evas_Object *obj, void *event_info);
static void _del_hook(Evas_Object *obj)
{
static void _theme_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
+ char buf[4096];
+
if (!wd) return;
_elm_theme_object_set(obj, wd->base, "searchbar", "base", elm_widget_style_get(obj));
if (wd->cancel_btn)
edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
+ snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
+ elm_object_style_set(wd->eb, buf);
+
+ snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
+ elm_object_style_set(wd->cancel_btn, buf);
+
edje_object_scale_set(wd->cancel_btn, elm_widget_scale_get(obj) * _elm_config->scale);
_sizing_eval(obj);
}
+static void
+_on_focus_hook(void *data, Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd || !wd->base)
+ return;
+ if (elm_widget_focus_get(obj))
+ {
+ if (wd->cancel_btn_show_mode)
+ {
+ if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
+ else edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
+ }
+ }
+}
+
static void _sizing_eval(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
evas_object_size_hint_max_set(obj, maxw, maxh);
}
-static void
-_searchicon_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
-{
- if (!strcmp(source, "search_icon"))
- evas_object_smart_callback_call(data, "searchsymbol,clicked", NULL);
-}
-
-static void _clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
+static void _clicked(void *data, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return;
- elm_entry_cursor_end_set(elm_editfield_entry_get(wd->eb));
- if (wd->cancel_btn_ani_flag == EINA_TRUE)
- edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
- else
- edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
+ if (wd->cancel_btn_show_mode)
+ {
+ if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELIN", "PROG");
+ else edje_object_signal_emit(wd->base, "CANCELSHOW", "PROG");
+ }
evas_object_smart_callback_call(data, "clicked", NULL);
}
-static void _changed(void *data, Evas_Object *obj, const char *emission, const char *source)
+static void _changed(void *data, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
// evas_object_smart_callback_call(data, "changed", NULL);
}
-static void _cancel_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
+static void _cancel_clicked(void *data, Evas_Object *obj, void *event_info)
{
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return;
- if (wd->cancel_btn_ani_flag == EINA_TRUE)
- edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
- else
- edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
+ if (wd->cancel_btn_show_mode)
+ {
+ if (wd->cancel_btn_ani_flag) edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
+ else edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
+ }
const char* text;
text = elm_entry_entry_get(elm_editfield_entry_get(wd->eb));
- if (text != NULL && strlen(text) > 0)
- elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
+ if (text != NULL && strlen(text) > 0) elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
evas_object_smart_callback_call(data, "cancel,clicked", NULL);
}
+static void
+_basebg_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
+{
+ Widget_Data *wd = elm_widget_data_get(data);
+
+ if (!wd) return;
+
+ if (!strcmp(source, "base_bg"))
+ _clicked(data, obj, NULL);
+}
+
+static void
+_searchsymbol_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
+{
+ Widget_Data *wd = elm_widget_data_get(data);
+
+ if (!wd) return;
+ evas_object_smart_callback_call(data, "searchsymbol,clicked", NULL);
+}
+
/**
* Add a new searchbar to the parent
* @param parent The parent object
Evas_Object *obj;
Evas *e;
Widget_Data *wd;
+ char buf[4096];
wd = ELM_NEW(Widget_Data);
e = evas_object_evas_get(parent);
elm_widget_data_set(obj, wd);
elm_widget_del_hook_set(obj, _del_hook);
elm_widget_theme_hook_set(obj, _theme_hook);
+ elm_widget_on_focus_hook_set( obj, _on_focus_hook, NULL );
elm_widget_can_focus_set(obj, 1 );
wd->base = edje_object_add(e);
// Add Entry
wd->eb = elm_editfield_add(parent);
- elm_object_style_set(wd->eb, "searchbar");
+ snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
+ elm_object_style_set(wd->eb, buf);
+
edje_object_part_swallow(wd->base, "search_textfield", wd->eb);
// elm_editfield_guide_text_set(wd->eb, "Search");
elm_editfield_entry_single_line_set(wd->eb, EINA_TRUE);
elm_editfield_eraser_set(wd->eb, EINA_TRUE);
evas_object_smart_callback_add(wd->eb, "clicked", _clicked, obj);
evas_object_smart_callback_add(elm_editfield_entry_get(wd->eb), "changed", _changed, obj);
- edje_object_signal_callback_add(wd->base, "mouse,up,1", "search_icon", _searchicon_clicked, obj);
+ edje_object_signal_callback_add(wd->base, "mouse,up,1", "*", _basebg_clicked, obj);
+ edje_object_signal_callback_add(wd->base, "elm,action,click", "", _searchsymbol_clicked, obj);
elm_widget_sub_object_add(obj, wd->eb);
// Add Button
wd->cancel_btn = elm_button_add(parent);
edje_object_part_swallow(wd->base, "button_cancel", wd->cancel_btn);
- elm_object_style_set(wd->cancel_btn, "custom/darkblue");
+
+ snprintf(buf, sizeof(buf), "searchbar/%s", elm_widget_style_get(obj));
+ elm_object_style_set(wd->cancel_btn, buf);
+
elm_button_label_set(wd->cancel_btn, "Cancel");
evas_object_smart_callback_add(wd->cancel_btn, "clicked", _cancel_clicked, obj);
elm_widget_sub_object_add(obj, wd->cancel_btn);
wd->cancel_btn_ani_flag = EINA_FALSE;
+ wd->cancel_btn_show_mode = EINA_TRUE;
+ wd->boundary_mode = EINA_TRUE;
elm_widget_resize_object_set(obj, wd->base);
EAPI void elm_searchbar_text_set(Evas_Object *obj, const char *entry)
{
Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return NULL;
+ if (!wd) return;
elm_entry_entry_set(elm_editfield_entry_get(wd->eb), entry);
}
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
- if (cancel_btn_ani_flag == EINA_TRUE)
- wd->cancel_btn_ani_flag = EINA_TRUE;
+ if (wd->cancel_btn_ani_flag == cancel_btn_ani_flag) return;
+ else wd->cancel_btn_ani_flag = cancel_btn_ani_flag;
+}
+
+/**
+ * set the cancel button show mode
+ *
+ * @param obj The searchbar object
+ * @param visible The flag of cancen button show or not
+ * @return void
+ *
+ * @ingroup Searchbar
+ */
+EAPI void elm_searchbar_cancel_button_set(Evas_Object *obj, Eina_Bool visible)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ if (wd->cancel_btn_show_mode == visible) return;
+ else wd->cancel_btn_show_mode = visible;
+
+ if (!visible)
+ {
+ if (wd->cancel_btn_ani_flag)
+ edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
+ else
+ edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
+ }
+ _sizing_eval(obj);
+}
+
+/**
+ * clear searchbar status
+ *
+ * @param obj The searchbar object
+ * @return void
+ *
+ * @ingroup Searchbar
+ */
+EAPI void elm_searchbar_clear(Evas_Object *obj)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ if (wd->cancel_btn_show_mode)
+ {
+ if (wd->cancel_btn_ani_flag)
+ edje_object_signal_emit(wd->base, "CANCELOUT", "PROG");
+ else
+ edje_object_signal_emit(wd->base, "CANCELHIDE", "PROG");
+ }
+// elm_entry_entry_set(elm_editfield_entry_get(wd->eb), NULL);
+}
+
+/**
+ * set the searchbar boundary rect mode(with bg rect) set
+ *
+ * @param obj The searchbar object
+ * @param boundary The present flag of boundary rect or not
+ * @return void
+ *
+ * @ingroup Searchbar
+ */
+EAPI void elm_searchbar_boundary_rect_set(Evas_Object *obj, Eina_Bool boundary)
+{
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ if (wd->boundary_mode == boundary) return;
+ else wd->boundary_mode = boundary;
+
+ if (wd->boundary_mode)
+ {
+ edje_object_signal_emit(wd->base, "BDSHOW", "PROG");
+ }
else
- wd->cancel_btn_ani_flag = EINA_FALSE;
+ {
+ edje_object_signal_emit(wd->base, "BDHIDE", "PROG");
+ }
+ _sizing_eval(obj);
}