4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include <setting-common-draw-widget.h>
25 * Get searchbar text and register redraw_cb by idler.
28 * @param[in] search_bar
29 * @param[in] search_text
30 * @param[in] search_idler
31 * @param[in] redraw_cb
33 int setting_searchbar_redraw(void *data,
34 Evas_Object *search_bar,
36 Ecore_Idler **search_idler,
37 Ecore_Task_Cb redraw_cb)
40 setting_retvm_if(search_bar == NULL, -1, "search_bar parameter is NULL");
41 //const char *str = elm_object_text_get(search_bar);
42 Evas_Object *entry = elm_object_part_content_get(search_bar, "elm.swallow.content");
43 const char *str = elm_entry_entry_get(entry);
44 int str_len = safeStrLen(str);
45 setting_retvm_if(str_len > MAX_SEARCH_STR_LEN, -1, "str_len > MAX_SEARCH_STR_LEN");
47 memset(search_text, '\0', MAX_SEARCH_STR_LEN + 1);
48 safeCopyStr(search_text, str, MAX_SEARCH_STR_LEN);
50 SETTING_TRACE("Update the search view text, search_text=%s",
54 ecore_idler_del(*search_idler);
57 *search_idler = ecore_idler_add(redraw_cb, data);
60 static void __searchbar_chg_cb(void *data, Evas_Object *obj, void *event_info)
62 Evas_Object *searchbar_layout = data;
63 if (elm_object_focus_get(searchbar_layout)) {
64 if (elm_entry_is_empty(obj)) {
65 elm_object_signal_emit(searchbar_layout, "elm,state,eraser,hide", "elm");
68 elm_object_signal_emit(searchbar_layout, "elm,state,eraser,show", "elm");
72 static void __searchbar_focused_cb(void *data, Evas_Object *obj, void *event_info)
74 ret_if(!data || !obj);
75 Evas_Object *searchbar_layout = data;
76 if (!elm_entry_is_empty(obj))
77 elm_object_signal_emit(searchbar_layout, "elm,state,eraser,show", "elm");
78 elm_object_signal_emit(searchbar_layout, "elm,state,guidetext,hide", "elm");
79 elm_object_signal_emit(searchbar_layout, "cancel,in", "");
82 static void __searchbar_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
84 ret_if(!data || !obj);
85 Evas_Object *searchbar_layout = data;
86 if (elm_entry_is_empty(obj))
87 elm_object_signal_emit(searchbar_layout, "elm,state,guidetext,show", "elm");
88 elm_object_signal_emit(searchbar_layout, "elm,state,eraser,hide", "elm");
91 static void __searchbar_eraser_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
94 Evas_Object *entry = data;
95 elm_entry_entry_set(entry, "");
98 static void __searchbar_bg_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
101 Evas_Object *entry = data;
102 elm_object_focus_set(entry, EINA_TRUE);
105 static void __searchbar_cancel_clicked_cb(void *data, Evas_Object *obj, void *event_info)
107 ret_if(!data || !obj);
108 evas_object_hide(obj);
109 Evas_Object *searchbar_layout = data;
110 elm_object_signal_emit(searchbar_layout, "cancel,out", "");
111 Evas_Object *entry = elm_object_part_content_get(searchbar_layout, "elm.swallow.content");
113 const char* text = elm_entry_entry_get(entry);
114 if (text != NULL && strlen(text) > 0)
115 elm_entry_entry_set(entry, NULL);
116 elm_object_focus_set(entry, EINA_FALSE);
119 static void __searchbar_searchsymbol_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
122 Evas_Object *entry = data;
123 elm_object_focus_set(entry, EINA_TRUE);
126 * Create searchar, register change cb and cancel cb.
130 * @param[in] change_cb
131 * @param[in] cancel_cb
133 Evas_Object *setting_create_searchbar(void *data, Evas_Object *parent,
134 Evas_Smart_Cb change_cb,
135 Evas_Smart_Cb cancel_cb)
138 setting_retvm_if(parent == NULL, NULL, "parent parameter is NULL");
139 Evas_Object *searchbar_layout = elm_layout_add(parent);
140 elm_layout_theme_set(searchbar_layout, "layout", "searchbar", "cancel_button");
141 elm_object_part_content_set(parent, "searchbar", searchbar_layout);
142 Evas_Object *entry = elm_entry_add(searchbar_layout);
143 elm_entry_scrollable_set(entry, EINA_TRUE);
144 elm_entry_single_line_set(entry, EINA_TRUE);
145 if (change_cb) evas_object_smart_callback_add(entry, "changed", change_cb, data);
146 evas_object_smart_callback_add(entry, "changed", __searchbar_chg_cb, searchbar_layout);
147 evas_object_smart_callback_add(entry, "focused", __searchbar_focused_cb, searchbar_layout);
148 evas_object_smart_callback_add(entry, "unfocused", __searchbar_unfocused_cb, searchbar_layout);
149 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NORMAL);
150 elm_object_part_content_set(searchbar_layout, "elm.swallow.content", entry);
151 elm_object_part_text_set(searchbar_layout, "elm.guidetext", _("IDS_COM_SK_SEARCH"));
152 elm_object_signal_callback_add(searchbar_layout, "elm,eraser,clicked", "elm", __searchbar_eraser_clicked_cb, entry);
153 elm_object_signal_callback_add(searchbar_layout, "elm,bg,clicked", "elm", __searchbar_bg_clicked_cb, entry);
154 evas_object_size_hint_weight_set(searchbar_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155 evas_object_size_hint_align_set(searchbar_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
158 Evas_Object *cancel_btn = elm_button_add(searchbar_layout);
159 elm_object_part_content_set(searchbar_layout, "button_cancel", cancel_btn);
160 elm_object_style_set(cancel_btn, "searchbar/default");
161 elm_object_text_set(cancel_btn, _("Cancel"));
164 cancel_cb = __searchbar_cancel_clicked_cb;
166 evas_object_smart_callback_add(cancel_btn, "clicked", cancel_cb, searchbar_layout);
167 elm_object_signal_callback_add(searchbar_layout, "elm,action,click", "", __searchbar_searchsymbol_clicked_cb, entry);
168 return searchbar_layout;