[Issues] TNEF-2062,TNEF-2056,TNEF-2055,TNEF-2129,
[profile/tv/apps/web/browser.git] / services / SimpleUI / SearchBox.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "SearchBox.h"
18 #include "BrowserLogger.h"
19
20 namespace tizen_browser
21 {
22 namespace base_ui
23 {
24
25 SearchBox::SearchBox(Evas_Object *parent)
26 {
27     std::string edjFilePath = EDJE_DIR;
28     edjFilePath.append("SimpleUI/SearchBox.edj");
29     elm_theme_extension_add(NULL, edjFilePath.c_str());
30
31     m_entry_layout = elm_layout_add(parent);
32     if(!elm_layout_file_set(m_entry_layout, edjFilePath.c_str(), "search_box"))
33         throw std::runtime_error("Layout file not found: " + edjFilePath);
34
35     m_webSearchEntry = elm_entry_add(m_entry_layout);
36
37     elm_object_style_set(m_webSearchEntry, "search_entry");
38
39     elm_entry_single_line_set(m_webSearchEntry, EINA_TRUE);
40     elm_entry_scrollable_set(m_webSearchEntry, EINA_TRUE);
41
42     search_caseSensitive = false;
43
44     elm_object_translatable_part_text_set(m_webSearchEntry, "elm.guide", "Search");
45
46     evas_object_smart_callback_add(m_webSearchEntry, "changed,user", SearchBox::searchNext, this);
47
48     //Add Case sensitive checkbox
49     m_caseSensitive = elm_check_add(m_entry_layout);
50     elm_object_part_text_set(m_caseSensitive, "default", "Match case");
51     elm_object_part_text_set(m_caseSensitive, "on", "Match case");
52     elm_object_part_text_set(m_caseSensitive, "off", "Match case");
53     elm_check_state_set(m_caseSensitive, EINA_FALSE);
54     elm_object_part_content_set(m_entry_layout, "search_opts_case", m_caseSensitive);
55
56     //Add prev and next buttons
57     m_searchPrev = elm_button_add(m_entry_layout);
58     elm_object_style_set(m_searchPrev, "default_button");
59     elm_object_part_text_set(m_searchPrev, "default", "Prev");
60     elm_object_part_content_set(m_entry_layout, "search_opts_prev", m_searchPrev);
61
62     m_searchNext = elm_button_add(m_entry_layout);
63     elm_object_style_set(m_searchNext, "default_button");
64     elm_object_part_text_set(m_searchNext, "default", "Next");
65     elm_object_part_content_set(m_entry_layout, "search_opts_next", m_searchNext);
66
67     evas_object_smart_callback_add(m_searchNext, "clicked", SearchBox::searchNext, this);
68     evas_object_smart_callback_add(m_searchPrev, "clicked", SearchBox::searchPrev, this);
69     evas_object_smart_callback_add(m_caseSensitive, "changed", SearchBox::caseSensitiveChanged, this);
70
71     elm_object_part_content_set(m_entry_layout, "search_entry_swallow", m_webSearchEntry);
72
73     hide();
74 }
75
76 Evas_Object* SearchBox::getContent()
77 {
78     return m_entry_layout;
79 }
80
81 void SearchBox::hide()
82 {
83     elm_object_signal_emit(m_entry_layout, "elm,state,hide", "elm");
84     elm_object_signal_emit(m_searchNext, "elm,state,hide", "elm");
85     elm_object_signal_emit(m_searchPrev, "elm,state,hide", "elm");
86     elm_object_signal_emit(m_webSearchEntry, "elm,state,hide", "elm");
87     elm_entry_entry_set(m_webSearchEntry, "");
88 //    evas_object_hide(m_caseSensitive);
89     visible = false;
90 }
91
92 void SearchBox::show()
93 {
94     elm_object_signal_emit(m_entry_layout, "elm,state,show", "elm");
95     elm_object_signal_emit(m_searchNext, "elm,state,show", "elm");
96     elm_object_signal_emit(m_searchPrev, "elm,state,show", "elm");
97     elm_object_signal_emit(m_webSearchEntry, "elm,state,show", "elm");
98 //    evas_object_show(m_caseSensitive);
99     visible = true;
100 }
101
102 bool SearchBox::is_visible()
103 {
104     return visible;
105 }
106
107 void SearchBox::searchNext(void *data, Evas_Object */*obj*/, void */*event_info*/)
108 {
109     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
110     SearchBox *self = reinterpret_cast<SearchBox*>(data);
111     std::string entry(elm_entry_markup_to_utf8(elm_entry_entry_get(self->m_webSearchEntry)));
112
113     if (self->search_caseSensitive)
114         self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT);
115     else
116         self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
117
118 }
119
120 void SearchBox::searchPrev(void *data, Evas_Object */*obj*/, void */*event_info*/)
121 {
122     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
123     SearchBox *self = reinterpret_cast<SearchBox*>(data);
124     std::string entry(elm_entry_markup_to_utf8(elm_entry_entry_get(self->m_webSearchEntry)));
125
126     if (self->search_caseSensitive)
127         self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_BACKWARDS);
128     else
129         self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE | EWK_FIND_OPTIONS_BACKWARDS);
130
131 }
132
133 void SearchBox::caseSensitiveChanged(void *data, Evas_Object */*obj*/, void */*event_info*/)
134 {
135     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
136     SearchBox *self = reinterpret_cast<SearchBox*>(data);
137     std::string entry(elm_entry_markup_to_utf8(elm_entry_entry_get(self->m_webSearchEntry)));
138     self->search_caseSensitive = elm_check_state_get(self->m_caseSensitive);
139
140     if (self->search_caseSensitive)
141         self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT);
142     else
143         self->textChanged(entry, EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
144 }
145
146
147 }
148
149 }
150