Remove global variables
[platform/core/uifw/ise-default.git] / src / ise-tutorial-mode.cpp
1 /*
2  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
18 #include "ise-tutorial-mode.h"
19 #include "ise.h"
20 #include <dlog.h>
21 #include <inputmethod.h>
22 #undef LOG_TAG
23 #define LOG_TAG "ISE_DEFAULT"
24
25 #define USE_EFL
26
27 #define OVERLAY_TITLE_WIDTH 190
28 #define OVERLAY_TITLE_HEIGHT 100
29
30 #define OVERLAY_CONTENT_WIDTH 294
31 #define OVERLAY_CONTENT_HEIGHT 111
32
33 #define GUIDE_TITLE_TEXT_FONT_DEFAULT_SIZE 36
34 #define GUIDE_TITLE_TEXT_FONT_MIN_SIZE 20
35
36 #define GUIDE_MAIN_TEXT_FONT_DEFAULT_SIZE 28
37 #define GUIDE_MAIN_TEXT_FONT_MIN_SIZE 10
38
39 #define BUTTON_WIDTH 56
40 #define BUTTON_HEIGHT 56
41 #define BUTTON_PADDING_X 152
42 #define BUTTON_PADDING_Y 289
43 #define BASE_WIDTH 360
44 #define BASE_HEIGHT 360
45
46 #define DEFAULT_FORMAT_GUIDE_TITLE_TEXT "DEFAULT='font=Tizen:style=Regular font_size=%d align=center color=#ffffff text_class=tizen wrap=mixed'"
47 #define DEFAULT_FORMAT_GUIDE_MAIN_TEXT "DEFAULT='font=Tizen:style=Large font_size=%d align=center color=#ffffff text_class=tizen wrap=mixed' newline='br'"
48
49 #define TUTORIAL_TITLE       dgettext(PACKAGE, "IDS_IME_BODY_USING_KEYBOARD_ABB")
50 #define TUTORIAL_CONTEXT_1   dgettext(PACKAGE, "IDS_TTRL_BODY_TURN_THE_BEZEL_CLOCKWISE_TO_VIEW_NUMBERS_AND_MORE_ABB")
51 #define TUTORIAL_CONTEXT_2   dgettext(PACKAGE, "IDS_TTRL_BODY_TURN_THE_BEZEL_ANTICLOCKWISE_TO_GET_STARTED_ABB")
52
53 static Evas_Object *main_window = NULL;
54 static Evas_Object *tutorial_window = NULL;
55 static Evas_Object *image_ob = NULL;
56 static Evas_Object *rotate = NULL;
57 static Evas_Object *button = NULL;
58 static Ecore_Timer *tutorial_window_create_timer = NULL;
59 static Ecore_Timer *tutorial_window_destory_timer = NULL;
60
61 static int SCREEN_WIDTH, SCREEN_HEIGHT;
62 static bool is_tutorial_show = false;
63
64 static sclu32 _context_layout = 0;
65
66 static Eina_Bool ise_destroy_tutorial_mode_cb(void *data);
67 static Eina_Bool tutorial_show_layout_cb(void *data);
68
69 #define EDJ_FILE_PATH                   RESDIR"/edje/wearable/tutorial_popup.edj"
70 #define IMG_POPUP_FC_BG                 LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_bg.png"
71 #define IMG_POPUP_TUTORIAL_CW           LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_rotate_cw.png"
72 #define IMG_POPUP_TUTORIAL_CCW          LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_rotate_ccw.png"
73 #define IMG_POPUP_BUTTON_OK_NORMAL      LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_att_ok_normal.png"
74 #define IMG_POPUP_BUTTON_OK_PRESS       LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_att_ok_press.png"
75 #define IMG_POPUP_BUTTON_CANCEL_NORMAL  LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_bt_cancel_normal.png"
76 #define IMG_POPUP_BUTTON_CANCEL_PRESS   LAYOUTDIR"/wearable/image/tutorial/gear_tutorial_bt_cancel_press.png"
77
78 void view_set_image(Evas_Object *parent, const char *part_name, const char *image_path)
79 {
80     Evas_Object *image = NULL;
81
82     if (parent == NULL) {
83         return;
84     }
85     image = elm_object_part_content_get(parent, part_name);
86     if (image == NULL) {
87         image = elm_image_add(parent);
88         if (image == NULL) {
89             return;
90         }
91         elm_object_part_content_set(parent, part_name, image);
92     }
93     if (EINA_FALSE == elm_image_file_set(image, image_path, NULL)) {
94         return;
95     }
96     evas_object_show(image);
97     return;
98 }
99
100 static void guide_popup_bt_close_cb(void *user_data, Evas *e, Evas_Object *obj, void *event_info)
101 {
102     view_set_image(button, NULL, IMG_POPUP_BUTTON_CANCEL_PRESS);
103     if (tutorial_window_destory_timer == NULL)
104         tutorial_window_destory_timer = ecore_timer_add(0.5,
105                                                         ise_destroy_tutorial_mode_cb,
106                                                         NULL);
107 }
108
109 void ise_show_tutorial_mode_popup(int type)
110 {
111     _context_layout = type;
112     main_window = ime_get_main_window();
113     elm_win_screen_size_get(main_window, NULL, NULL, &SCREEN_WIDTH, &SCREEN_HEIGHT);
114     ise_destroy_tutorial_mode_popup();
115
116     if (tutorial_window_create_timer == NULL)
117         tutorial_window_create_timer = ecore_timer_add(0,
118                                                        tutorial_show_layout_cb,
119                                                        NULL);
120 }
121
122 static Eina_Bool ise_destroy_tutorial_mode_cb(void *data)
123 {
124     ise_destroy_tutorial_mode_popup();
125     return ECORE_CALLBACK_CANCEL;
126 }
127
128 static Eina_Bool tutorial_show_layout_cb(void *data)
129 {
130     if (!tutorial_window) {
131         tutorial_window = elm_win_add(main_window, NULL,
132                                         ELM_WIN_UTILITY);
133         elm_win_borderless_set(tutorial_window, EINA_TRUE);
134         elm_win_alpha_set(tutorial_window, EINA_TRUE);
135         elm_win_title_set(tutorial_window, "ISF Popup");
136
137         elm_win_aux_hint_add(tutorial_window, "wm.policy.win.rot.dependent", "1");
138
139         // accepts focus
140         elm_win_prop_focus_skip_set(tutorial_window, EINA_TRUE);
141
142         evas_object_resize(tutorial_window, SCREEN_WIDTH, SCREEN_HEIGHT);
143         evas_object_move(tutorial_window, 0, 0);
144         evas_object_show(tutorial_window);
145         elm_win_raise(tutorial_window);
146
147         image_ob = evas_object_image_add(evas_object_evas_get(tutorial_window));
148         evas_object_image_file_set(image_ob, IMG_POPUP_FC_BG, NULL);
149         evas_object_image_border_set(image_ob, 0, 0, 0, 0);
150         Evas_Load_Error err_image = evas_object_image_load_error_get(image_ob);
151         if (err_image != EVAS_LOAD_ERROR_NONE) {
152             LOGD("Could not load image, error string is \"%s\"", evas_load_error_str(err_image));
153         } else {
154             evas_object_image_fill_set(image_ob, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
155             evas_object_resize(image_ob, SCREEN_WIDTH, SCREEN_HEIGHT);
156             evas_object_move(image_ob, 0, 0);
157             evas_object_layer_set(image_ob, EVAS_LAYER_MAX);
158             evas_object_show(image_ob);
159         }
160
161         rotate = evas_object_image_add(evas_object_evas_get(tutorial_window));
162         if (_context_layout == ISE_LAYOUT_STYLE_NORMAL) {
163             evas_object_image_file_set(rotate, IMG_POPUP_TUTORIAL_CW, NULL);
164         } else if (_context_layout == ISE_LAYOUT_STYLE_NUMBER) {
165             evas_object_image_file_set(rotate, IMG_POPUP_TUTORIAL_CCW, NULL);
166         }
167         evas_object_image_border_set(rotate, 0, 0, 0, 0);
168
169         Evas_Load_Error err_rotate = evas_object_image_load_error_get(rotate);
170         if (err_rotate != EVAS_LOAD_ERROR_NONE) {
171             LOGD("Could not load image, error string is \"%s\"", evas_load_error_str(err_rotate));
172         } else {
173             evas_object_image_fill_set(rotate, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
174             evas_object_resize(rotate, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
175             evas_object_move(rotate, 0, 0);
176             evas_object_layer_set(rotate, EVAS_LAYER_MAX);
177             evas_object_show(rotate);
178         }
179
180         Evas_Object *context = edje_object_add(evas_object_evas_get(tutorial_window));
181         evas_object_layer_set(context, EVAS_LAYER_MAX);
182         edje_object_file_set(context, EDJ_FILE_PATH, "main");
183         evas_object_resize(context, SCREEN_WIDTH, SCREEN_HEIGHT);
184         evas_object_move(context, 0, 0);
185
186         if (_context_layout == ISE_LAYOUT_STYLE_NORMAL) {
187             edje_object_part_text_set(context, "title", TUTORIAL_TITLE);
188             edje_object_part_text_set(context, "context1", TUTORIAL_CONTEXT_1);
189
190             button = elm_button_add(tutorial_window);
191             elm_object_style_set(button, "focus");
192             view_set_image(button, NULL, IMG_POPUP_BUTTON_CANCEL_NORMAL);
193             evas_object_resize(button, BUTTON_WIDTH*SCREEN_WIDTH/BASE_WIDTH, BUTTON_HEIGHT*SCREEN_HEIGHT/BASE_HEIGHT);
194             evas_object_move(button, BUTTON_PADDING_X*SCREEN_WIDTH/BASE_WIDTH, BUTTON_PADDING_Y*SCREEN_HEIGHT/BASE_HEIGHT);
195             evas_object_layer_set(button, EVAS_LAYER_MAX);
196             evas_object_show(button);
197
198             evas_object_event_callback_add(button, EVAS_CALLBACK_MOUSE_DOWN, guide_popup_bt_close_cb, NULL);
199         } else if (_context_layout == ISE_LAYOUT_STYLE_NUMBER) {
200             edje_object_part_text_set(context, "context2", TUTORIAL_CONTEXT_2);
201         }
202         evas_object_show(context);
203
204         is_tutorial_show = true;
205     }
206     return ECORE_CALLBACK_CANCEL;
207 }
208
209 void ise_destroy_tutorial_mode_popup()
210 {
211     if (tutorial_window) {
212         evas_object_del(tutorial_window);
213         tutorial_window = NULL;
214     }
215
216     if (image_ob) {
217         evas_object_del(image_ob);
218         image_ob = NULL;
219     }
220
221     if (rotate) {
222         evas_object_del(rotate);
223         rotate = NULL;
224     }
225
226     if (tutorial_window_create_timer) {
227         ecore_timer_del(tutorial_window_create_timer);
228         tutorial_window_create_timer = NULL;
229     }
230
231     if (tutorial_window_destory_timer) {
232         ecore_timer_del(tutorial_window_destory_timer);
233         tutorial_window_destory_timer = NULL;
234     }
235
236     is_tutorial_show = false;
237 }
238
239 bool check_is_tutorial_show()
240 {
241     return is_tutorial_show;
242 }