Split guide popup code into another file 20/261420/4
authorJihoon Kim <jihoon48.kim@samsung.com>
Sat, 17 Jul 2021 07:16:37 +0000 (16:16 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Mon, 19 Jul 2021 10:08:45 +0000 (19:08 +0900)
Change-Id: I53b8c121f56ea5b48c8af7ccadbe6aedbd53adf3
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
src/guidepopup.cpp [new file with mode: 0644]
src/include/guidepopup.h [new file with mode: 0644]
src/ise.cpp

index ac1cf11..b2449ee 100644 (file)
@@ -25,6 +25,7 @@ SET(ISE_SRCS
     src/candidate-efl.cpp
     src/candidate-multiline-efl.cpp
     src/autofill.cpp
+    src/guidepopup.cpp
     src/ise-dbus.cpp
     src/ise-sticker-mode.cpp
     src/nmt.cpp
diff --git a/src/guidepopup.cpp b/src/guidepopup.cpp
new file mode 100644 (file)
index 0000000..85b923f
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "ise.h"
+#include "config.h"
+#include "sdk.h"
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "ISE_DEFAULT"
+
+#define EDJ_FILE                        RESDIR"/edje/" PROFILE_NAME"/customised_ctxpopup.edj"
+
+static Evas_Object* _guide_popup_setting = NULL;
+static Evas_Object* _guide_popup_space = NULL;
+
+bool guide_popup_get_visible()
+{
+    return _guide_popup_setting ? true : false;
+}
+
+Evas_Object *open_message_popup(Evas_Object *parentWnd)
+{
+    static Evas_Object *msg_window = NULL;
+    if (msg_window) {
+        evas_object_del(msg_window);
+        msg_window = NULL;
+    }
+    msg_window = elm_win_add(parentWnd, "MCFMessagePopup", ELM_WIN_UTILITY);
+    if (msg_window) {
+        int w, h;
+        elm_win_borderless_set(msg_window, EINA_TRUE);
+        elm_win_alpha_set(msg_window, EINA_TRUE);
+        elm_win_title_set(msg_window, "ISF Popup");
+        elm_win_screen_size_get(msg_window, NULL, NULL, &w, &h);
+        elm_win_prop_focus_skip_set(msg_window, TRUE);
+        int rots[4] = {0, 90, 180, 270};
+        elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
+        evas_object_resize(msg_window, w, h);
+    }
+
+    int rots[4] = { 0, 90, 180, 270 };
+    elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
+    evas_object_show(msg_window);
+    return msg_window;
+}
+
+void ise_destroy_popup_space()
+{
+    if (_guide_popup_space != NULL) {
+        LOGD("destroy space popup iter\n");
+        evas_object_del(_guide_popup_space);
+        _guide_popup_setting = NULL;
+        CONFIG_VALUES *config_values = get_config_values();
+        if (config_values) {
+            config_values->first_guidechange = TRUE;
+        }
+        write_ise_config_values();
+    }
+}
+
+void ise_destroy_popup_setting()
+{
+    if (_guide_popup_setting != NULL) {
+        LOGD("destroy setting popup iter\n");
+        evas_object_del(_guide_popup_setting);
+        _guide_popup_setting = NULL;
+        CONFIG_VALUES *config_values = get_config_values();
+        if (config_values) {
+            config_values->first_guideset = TRUE;
+        }
+        write_ise_config_values();
+    }
+}
+
+void _guideline_popup_space_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_space_cb);
+    evas_object_del(obj);
+    obj = NULL;
+    ise_destroy_popup_space();
+    CONFIG_VALUES *config_values = get_config_values();
+    if (config_values) {
+        config_values->first_guidechange = TRUE;
+    }
+    write_ise_config_values();
+}
+
+void _guideline_popup_setting_cb(void *data, Evas_Object *obj, void *event_info)
+{
+    evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_setting_cb);
+    evas_object_del(obj);
+    obj = NULL;
+    ise_destroy_popup_setting();
+    CONFIG_VALUES *config_values = get_config_values();
+    if (config_values) {
+        config_values->first_guideset = TRUE;
+    }
+    write_ise_config_values();
+}
+
+void ise_show_help_popup(sclulong keyEvent, Evas_Object *win)
+{
+    char buf[2048] = {0, };
+    int font_size = 40;
+    sclint scr_w = 0;
+    sclint scr_h = 0;
+    SclRectangle rectangle = {0};
+    Evas_Object *ctxpopup = NULL;
+    Elm_Theme *theme = NULL;
+
+    CSCLUI *ui = get_ui();
+    if (ui) {
+        ui->get_screen_resolution(&scr_w, &scr_h);
+
+        if (keyEvent == MVK_space) {
+            CONFIG_VALUES *config_values = get_config_values();
+            if (config_values) {
+                config_values->first_guidechange = TRUE;
+            }
+            write_ise_config_values();
+            ui->get_button_geometry("SPACE_KEY", &rectangle);
+            _guide_popup_space = open_message_popup(win);
+
+            theme = elm_theme_new();
+            elm_theme_ref_set(theme, NULL);
+            elm_theme_extension_add(theme, EDJ_FILE);
+
+            ctxpopup = elm_ctxpopup_add(_guide_popup_space);
+            elm_object_theme_set(ctxpopup, theme);
+            evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_space_cb, (void *)keyEvent);
+        } else {
+            CONFIG_VALUES *config_values = get_config_values();
+            if (config_values) {
+                config_values->first_guideset = TRUE;
+            }
+            write_ise_config_values();
+            ui->get_button_geometry("CM_KEY", &rectangle);
+            _guide_popup_setting = open_message_popup(win);
+            theme = elm_theme_new();
+            elm_theme_ref_set(theme, NULL);
+            elm_theme_extension_add(theme, EDJ_FILE);
+            ctxpopup = elm_ctxpopup_add(_guide_popup_setting);
+            elm_object_theme_set(ctxpopup, theme);
+            evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_setting_cb, (void *)keyEvent);
+        }
+    }
+
+    int rotation = elm_win_rotation_get(win);
+    bool landscape_device = get_landscape_device(rotation);
+    if (rotation == 0 || rotation == 180) {
+        elm_object_style_set(ctxpopup, landscape_device ? "customised_guideline_popup_landscape" : "customised_guideline_popup");
+    } else {
+        elm_object_style_set(ctxpopup, landscape_device ?  "customised_guideline_popup" : "customised_guideline_popup_landscape");
+    }
+
+    elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
+                          ELM_CTXPOPUP_DIRECTION_UNKNOWN,
+                          ELM_CTXPOPUP_DIRECTION_UNKNOWN,
+                          ELM_CTXPOPUP_DIRECTION_UNKNOWN);
+
+    Evas_Object* text = elm_label_add(ctxpopup);
+
+    if (keyEvent == MVK_space) {
+        snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
+            dgettext(PACKAGE, "IDS_IME_BODY_SWIPE_THE_SPACE_BAR_LEFT_OR_RIGHT_TO_CHANGE_BETWEEN_LANGUAGES"));
+    } else {
+        snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
+               dgettext(PACKAGE, "IDS_IME_BODY_TAP_AND_HOLD_THIS_KEY_TO_SEE_THE_SYMBOL_LIST_SELECT_ONE_TO_USE_IT_AS_A_SHORTCUT"));
+    }
+    elm_object_text_set(text, buf);
+    elm_object_content_set(ctxpopup, text);
+    Evas_Coord x, y, w, h;
+    evas_object_geometry_get(win, &x, &y, &w, &h);
+
+    if (rotation == 0 || rotation == 180) {
+        elm_label_wrap_width_set(text, (scr_w * 4) / 5);
+        evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(50));
+        evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(600));
+        evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
+                    (scr_h - h) + rectangle.y - ELM_SCALE_SIZE(5));
+    } else {
+        elm_label_wrap_width_set(text, (scr_h * 4) / 5);
+        evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(50));
+        evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(600));
+        evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
+                (scr_w - h)+ rectangle.y - ELM_SCALE_SIZE(5));
+    }
+    elm_label_line_wrap_set(text, ELM_WRAP_MIXED);
+    evas_object_show(text);
+
+    if (keyEvent == MVK_space) {
+        evas_object_layer_set(_guide_popup_space, EVAS_LAYER_MAX);
+        evas_object_show(_guide_popup_space);
+    } else {
+        evas_object_layer_set(_guide_popup_setting, EVAS_LAYER_MAX);
+        evas_object_show(_guide_popup_setting);
+    }
+
+    evas_object_layer_set(ctxpopup, EVAS_LAYER_MAX);
+    evas_object_show(ctxpopup);
+}
diff --git a/src/include/guidepopup.h b/src/include/guidepopup.h
new file mode 100644 (file)
index 0000000..3a566c5
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _GUIDEPOPUP_H_
+#define _GUIDEPOPUP_H_
+
+#include <Evas.h>
+
+bool guide_popup_get_visible();
+void ise_show_help_popup(sclulong keyEvent, Evas_Object *win);
+void ise_destroy_popup_space();
+void ise_destroy_popup_setting();
+
+#endif
index 1d80c7c..40ddfba 100644 (file)
@@ -52,8 +52,7 @@
 #include "ise-sticker-mode.h"
 #include "ise-nmt-mode.h"
 #include "nmt.h"
-
-#define EDJ_FILE                        RESDIR"/edje/" PROFILE_NAME"/customised_ctxpopup.edj"
+#include "guidepopup.h"
 
 #define EXIT_ISE_ON_HIDE 0
 #define DEFER_ISE_CREATION 0
@@ -225,8 +224,6 @@ static sclboolean           _cm_popup_opened = FALSE;
 static const char          *_cm_key_list[CM_KEY_LIST_SIZE] = {USER_KEYSTRING_OPTION, USER_KEYSTRING_EMOTICON, USER_KEYSTRING_CLIPBOARD,
                                                               USER_KEYSTRING_VOICE, USER_KEYSTRING_FLOATING, USER_KEYSTRING_STICKER, USER_KEYSTRING_TRANSLATION};
 static scluint              _current_cm_key_id = 0;
-static Evas_Object* _guide_popup_setting = NULL;
-static Evas_Object* _guide_popup_space = NULL;
 
 /*
  * This callback class will receive all response events from SCL
@@ -831,86 +828,6 @@ SCLEventReturnType CUIEventCallback::on_event_notification(SCLUINotiType noti_ty
     return ret;
 }
 
-void ise_destroy_popup_setting()
-{
-    if (_guide_popup_setting != NULL) {
-        LOGD("destroy setting popup iter\n");
-        evas_object_del(_guide_popup_setting);
-        _guide_popup_setting = NULL;
-        CONFIG_VALUES *config_values = get_config_values();
-        if (config_values) {
-            config_values->first_guideset = TRUE;
-        }
-        write_ise_config_values();
-    }
-}
-
-void ise_destroy_popup_space()
-{
-    if (_guide_popup_space != NULL) {
-        LOGD("destroy space popup iter\n");
-        evas_object_del(_guide_popup_space);
-        _guide_popup_setting = NULL;
-        CONFIG_VALUES *config_values = get_config_values();
-        if (config_values) {
-            config_values->first_guidechange = TRUE;
-        }
-        write_ise_config_values();
-    }
-}
-
-Evas_Object *open_message_popup(Evas_Object *parentWnd)
-{
-    static Evas_Object *msg_window = NULL;
-    if (msg_window) {
-        evas_object_del(msg_window);
-        msg_window = NULL;
-    }
-    msg_window = elm_win_add(parentWnd, "MCFMessagePopup", ELM_WIN_UTILITY);
-    if (msg_window) {
-        int w, h;
-        elm_win_borderless_set(msg_window, EINA_TRUE);
-        elm_win_alpha_set(msg_window, EINA_TRUE);
-        elm_win_title_set(msg_window, "ISF Popup");
-        elm_win_screen_size_get(msg_window, NULL, NULL, &w, &h);
-        elm_win_prop_focus_skip_set(msg_window, TRUE);
-        int rots[4] = {0, 90, 180, 270};
-        elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
-        evas_object_resize(msg_window, w, h);
-    }
-
-    int rots[4] = { 0, 90, 180, 270 };
-    elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
-    evas_object_show(msg_window);
-    return msg_window;
-}
-
-void _guideline_popup_setting_cb(void *data, Evas_Object *obj, void *event_info)
-{
-    evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_setting_cb);
-    evas_object_del(obj);
-    obj = NULL;
-    ise_destroy_popup_setting();
-    CONFIG_VALUES *config_values = get_config_values();
-    if (config_values) {
-        config_values->first_guideset = TRUE;
-    }
-    write_ise_config_values();
-}
-
-void _guideline_popup_space_cb(void *data, Evas_Object *obj, void *event_info)
-{
-    evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_space_cb);
-    evas_object_del(obj);
-    obj = NULL;
-    ise_destroy_popup_space();
-    CONFIG_VALUES *config_values = get_config_values();
-    if (config_values) {
-        config_values->first_guidechange = TRUE;
-    }
-    write_ise_config_values();
-}
-
 bool get_landscape_device(int degree)
 {
     sclint width = 0;
@@ -934,108 +851,6 @@ bool get_landscape_device(int degree)
     return landscape_device;
 }
 
-void ise_show_help_popup(sclulong keyEvent)
-{
-    char buf[2048] = {0, };
-    int font_size = 40;
-    sclint scr_w = 0;
-    sclint scr_h = 0;
-    SclRectangle rectangle = {0};
-    Evas_Object *ctxpopup = NULL;
-    Elm_Theme *theme = NULL;
-
-    CSCLUI *ui = get_ui();
-    if (ui) {
-        ui->get_screen_resolution(&scr_w, &scr_h);
-
-        if (keyEvent == MVK_space) {
-            CONFIG_VALUES *config_values = get_config_values();
-            if (config_values) {
-                config_values->first_guidechange = TRUE;
-            }
-            write_ise_config_values();
-            ui->get_button_geometry("SPACE_KEY", &rectangle);
-            _guide_popup_space = open_message_popup(NATIVE_WINDOW_CAST(ime_get_main_window()));
-
-            theme = elm_theme_new();
-            elm_theme_ref_set(theme, NULL);
-            elm_theme_extension_add(theme, EDJ_FILE);
-
-            ctxpopup = elm_ctxpopup_add(_guide_popup_space);
-            elm_object_theme_set(ctxpopup, theme);
-            evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_space_cb, (void *)keyEvent);
-        } else {
-            CONFIG_VALUES *config_values = get_config_values();
-            if (config_values) {
-                config_values->first_guideset = TRUE;
-            }
-            write_ise_config_values();
-            ui->get_button_geometry("CM_KEY", &rectangle);
-            _guide_popup_setting = open_message_popup(NATIVE_WINDOW_CAST(ime_get_main_window()));
-            theme = elm_theme_new();
-            elm_theme_ref_set(theme, NULL);
-            elm_theme_extension_add(theme, EDJ_FILE);
-            ctxpopup = elm_ctxpopup_add(_guide_popup_setting);
-            elm_object_theme_set(ctxpopup, theme);
-            evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_setting_cb, (void *)keyEvent);
-        }
-    }
-
-    int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
-    bool landscape_device = get_landscape_device(rotation);
-    if (rotation == 0 || rotation == 180) {
-        elm_object_style_set(ctxpopup, landscape_device ? "customised_guideline_popup_landscape" : "customised_guideline_popup");
-    } else {
-        elm_object_style_set(ctxpopup, landscape_device ?  "customised_guideline_popup" : "customised_guideline_popup_landscape");
-    }
-
-    elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
-                          ELM_CTXPOPUP_DIRECTION_UNKNOWN,
-                          ELM_CTXPOPUP_DIRECTION_UNKNOWN,
-                          ELM_CTXPOPUP_DIRECTION_UNKNOWN);
-
-    Evas_Object* text = elm_label_add(ctxpopup);
-
-    if (keyEvent == MVK_space) {
-        snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
-            dgettext(PACKAGE, "IDS_IME_BODY_SWIPE_THE_SPACE_BAR_LEFT_OR_RIGHT_TO_CHANGE_BETWEEN_LANGUAGES"));
-    } else {
-        snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
-               dgettext(PACKAGE, "IDS_IME_BODY_TAP_AND_HOLD_THIS_KEY_TO_SEE_THE_SYMBOL_LIST_SELECT_ONE_TO_USE_IT_AS_A_SHORTCUT"));
-    }
-    elm_object_text_set(text, buf);
-    elm_object_content_set(ctxpopup, text);
-    Evas_Coord x, y, w, h;
-    evas_object_geometry_get(NATIVE_WINDOW_CAST(ime_get_main_window()), &x, &y, &w, &h);
-
-    if (rotation == 0 || rotation == 180) {
-        elm_label_wrap_width_set(text, (scr_w * 4) / 5);
-        evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(50));
-        evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(600));
-        evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
-                    (scr_h - h) + rectangle.y - ELM_SCALE_SIZE(5));
-    } else {
-        elm_label_wrap_width_set(text, (scr_h * 4) / 5);
-        evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(50));
-        evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(600));
-        evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
-                (scr_w - h)+ rectangle.y - ELM_SCALE_SIZE(5));
-    }
-    elm_label_line_wrap_set(text, ELM_WRAP_MIXED);
-    evas_object_show(text);
-
-    if (keyEvent == MVK_space) {
-        evas_object_layer_set(_guide_popup_space, EVAS_LAYER_MAX);
-        evas_object_show(_guide_popup_space);
-    } else {
-        evas_object_layer_set(_guide_popup_setting, EVAS_LAYER_MAX);
-        evas_object_show(_guide_popup_setting);
-    }
-
-    evas_object_layer_set(ctxpopup, EVAS_LAYER_MAX);
-    evas_object_show(ctxpopup);
-}
-
 SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc event_desc)
 {
     SECURE_LOGD("button %s is clicked\n", event_desc.key_value);
@@ -1058,7 +873,7 @@ SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc
         CONFIG_VALUES *config_values = get_config_values();
 
         if (config_values && (!config_values->first_guideset) && event_desc.key_value && (strncmp(event_desc.key_value, "OPTION", strlen(event_desc.key_value)) == 0)) {
-            ise_show_help_popup(event_desc.key_event);//show help popup in on_event_drag_state_changed other than on_event_key_clicked for fixing help popup show delay issue
+            ise_show_help_popup(event_desc.key_event, NATIVE_WINDOW_CAST(ime_get_main_window()));//show help popup in on_event_drag_state_changed other than on_event_key_clicked for fixing help popup show delay issue
             LOGD("setting popup show\n");
             return SCL_EVENT_PASS_ON;
         } else {
@@ -1288,7 +1103,7 @@ SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_d
            }
         case KEY_TYPE_MODECHANGE:
 #if defined(_MOBILE) || defined(_COMMON)
-            if (_guide_popup_setting != NULL) {//popup is showing
+            if (guide_popup_get_visible()) {//popup is showing
                 break;
             }
 #endif
@@ -1803,7 +1618,7 @@ ise_show(int ic)
 #if defined(_MOBILE) || defined(_COMMON)
         if (ise_is_guideline_popup_enable_layout()) {
             if ((config_values && config_values->first_guidechange) && (_language_manager.get_enabled_languages_num() > 1)) {
-                ise_show_help_popup(MVK_space);
+                ise_show_help_popup(MVK_space, NATIVE_WINDOW_CAST(ime_get_main_window()));
                 LOGD("space popup show\n");
             } else {
                 ise_destroy_popup_space();