TizenRefApp-6807 Implement text copy in the Event Details 46/82846/4
authorNataliia Kamyshna <n.kamyshna@samsung.com>
Mon, 8 Aug 2016 06:45:02 +0000 (09:45 +0300)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 11 Aug 2016 08:16:42 +0000 (01:16 -0700)
Change-Id: I0dfa13ea5b6fa2f3bffc1b4111fc4c00b74e2698
Signed-off-by: Nataliia Kamyshna <n.kamyshna@samsung.com>
common/fw/CalDialogControl.cpp
common/fw/CalDialogControl.h
main-app/src/detail/CalDetailView.cpp
main-app/src/detail/CalDialogDetailCopyableItem.cpp [new file with mode: 0644]
main-app/src/detail/CalDialogDetailCopyableItem.h [new file with mode: 0644]
main-app/src/detail/CalDialogDetailDescriptionItem.cpp
main-app/src/detail/CalDialogDetailDescriptionItem.h
main-app/src/detail/CalDialogDetailLocationItem.cpp
main-app/src/detail/CalDialogDetailLocationItem.h

index 1855b22..2c3f73a 100644 (file)
 #include "CalDialogControl.h"
 #include "CalCommon.h"
 
-CalDialogControl::Item::Item(int sortIndex) :
-       __isGroupTitle(false),
-       __sortIndex(sortIndex),
-       __customData(nullptr)
+CalDialogControl::Item::Item(int sortIndex)
+       : __isGroupTitle(false)
+       , __sortIndex(sortIndex)
+       , __customData(nullptr)
+       , __isLongpressed(false)
 
 {
 }
@@ -64,6 +65,20 @@ int CalDialogControl::Item::getSystemFontSize()
        return fontSize;
 }
 
+void CalDialogControl::Item::onLongpressed()
+{
+       __isLongpressed = onLongpress();
+}
+
+void CalDialogControl::Item::onSelected()
+{
+       if (__isLongpressed) {
+               __isLongpressed = false;
+               return;
+       }
+       onSelect();
+}
+
 CalDialogControl::CalDialogControl()
 {
        WENTER();
@@ -87,6 +102,12 @@ Evas_Object* CalDialogControl::onCreate(Evas_Object* parent, void* param)
        evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        elm_scroller_policy_set(genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
        elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+       evas_object_smart_callback_add(genlist, "longpressed", [](void *data, Evas_Object *obj, void *event_info) {
+               CalDialogControl::Item *item = (CalDialogControl::Item *) elm_object_item_data_get((Elm_Object_Item *) event_info);
+               if (item) {
+                       item->onLongpressed();
+               }
+       }, nullptr);
        evas_object_show(genlist);
 
        WLEAVE();
@@ -111,7 +132,7 @@ Elm_Object_Item* CalDialogControl::add(CalDialogControl::Item* item)
                                elm_genlist_item_selected_set(genlistItem, EINA_FALSE);
                                CalDialogControl::Item* item = (CalDialogControl::Item*)data;
 
-                               item->onSelect();
+                               item->onSelected();
                                WHIT();
                        }, item);
 
index ccba21c..7ce3afd 100644 (file)
@@ -64,6 +64,13 @@ public:
                virtual void onSelect();
 
                /**
+                * @brief Called when item is longpressed.
+                *
+                * @return Whether event is handled and onSelect() shouldn't be called.
+                */
+               virtual bool onLongpress() {return false;}
+
+               /**
                 * @brief Get sort index.
                 *
                 * @return Sort index.
@@ -116,8 +123,12 @@ public:
                bool __isGroupTitle;
 
        private:
+               void onSelected();
+               void onLongpressed();
+
                int __sortIndex;
-               void* __customData;
+               void *__customData;
+               bool __isLongpressed;
 
                friend class CalDialogControl;
        };
index 30a6081..116378b 100644 (file)
@@ -279,9 +279,6 @@ void CalDetailView::__update()
        __workingCopy->getDisplayLocation(-1, location);
        if (!location.empty()) {
                item = __dialog->add(new CalDialogDetailLocationItem(location.c_str()));
-               if (item) {
-                       elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
-               }
        }
 
        // Reminders
@@ -319,9 +316,6 @@ void CalDetailView::__update()
        if (!description.empty()) {
                __description = new CalDialogDetailDescriptionItem(description.c_str());
                item = __dialog->add(__description);
-               if (item) {
-                       elm_genlist_item_select_mode_set(item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
-               }
        }
 }
 
diff --git a/main-app/src/detail/CalDialogDetailCopyableItem.cpp b/main-app/src/detail/CalDialogDetailCopyableItem.cpp
new file mode 100644 (file)
index 0000000..6242ebe
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2016 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 "CalCommon.h"
+#include "CalDialogDetailCopyableItem.h"
+
+#include <efl_extension.h>
+
+#define LIST_COPY_POPUP_PAD 58 //LIST_TEXT_SUB_HEIGHT + LIST_WRAP_PADDING_TOP_SIZE
+
+CalDialogDetailCopyableItem::CalDialogDetailCopyableItem()
+       : __isSelecting(false)
+{
+}
+
+bool CalDialogDetailCopyableItem::isSelecting()
+{
+       return __isSelecting;
+}
+
+void CalDialogDetailCopyableItem::copyText(const char *text)
+{
+       elm_cnp_selection_set(elm_object_item_widget_get(getElmObjectItem()), ELM_SEL_TYPE_CLIPBOARD,
+                       ELM_SEL_FORMAT_TEXT, text, strlen(text));
+}
+
+bool CalDialogDetailCopyableItem::onLongpress()
+{
+       updateSelecting(true);
+
+       int x, y, w, h;
+       Evas_Object *rect = elm_object_item_track(getElmObjectItem());
+       evas_object_geometry_get(rect, &x, &y, &w, &h);
+       elm_object_item_untrack(getElmObjectItem());
+
+       Evas_Object *win = elm_object_top_widget_get(elm_object_item_widget_get(getElmObjectItem()));
+       createPopup(win, _L_("IDS_CLD_OPT_COPY"), x, y + LIST_COPY_POPUP_PAD);
+
+       return true;
+}
+
+void CalDialogDetailCopyableItem::createPopup(Evas_Object *parent, const char *text, int x, int y)
+{
+       Evas_Object *popup = elm_ctxpopup_add(parent);
+       elm_ctxpopup_horizontal_set(popup, EINA_TRUE);
+       elm_object_style_set(popup, "default");
+
+       evas_object_smart_callback_add(popup, "dismissed",
+                       [] (void *data, Evas_Object *obj, void *event_info) {
+                               CalDialogDetailCopyableItem *item = (CalDialogDetailCopyableItem *)data;
+                               item->updateSelecting(false);
+                               evas_object_del(obj);
+                       }, this);
+       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK,
+                       eext_ctxpopup_back_cb, nullptr);
+       eext_object_event_callback_add(popup, EEXT_CALLBACK_MORE,
+                       eext_ctxpopup_back_cb, nullptr);
+
+       Elm_Object_Item *item = elm_ctxpopup_item_append(popup, text, nullptr,
+                       [] (void *data, Evas_Object *obj, void *event_info) {
+                               CalDialogDetailCopyableItem *item = (CalDialogDetailCopyableItem *)data;
+                               item->onCopySelected();
+                               elm_ctxpopup_dismiss(obj);
+                       }, this);
+       elm_object_item_text_translatable_set(item, EINA_TRUE);
+
+       evas_object_move(popup, x, y);
+       evas_object_show(popup);
+}
+
+void CalDialogDetailCopyableItem::updateSelecting(bool isSelecting)
+{
+       if (__isSelecting != isSelecting) {
+               __isSelecting = isSelecting;
+               elm_genlist_item_fields_update(getElmObjectItem(), "elm.text.multiline", ELM_GENLIST_ITEM_FIELD_TEXT);
+       }
+}
diff --git a/main-app/src/detail/CalDialogDetailCopyableItem.h b/main-app/src/detail/CalDialogDetailCopyableItem.h
new file mode 100644 (file)
index 0000000..f71eb54
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2016 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.
+ *
+ */
+
+#ifndef _CAL_DIALOG_DETAIL_COPYABLE_ITEM_H_
+#define _CAL_DIALOG_DETAIL_COPYABLE_ITEM_H_
+
+#include <string>
+#include "CalDialogControl.h"
+
+/**
+ * @brief Calendar dialog detail copyable item.
+ *
+ * @see CalDialogControl::Item
+ */
+class CalDialogDetailCopyableItem : public CalDialogControl::Item
+{
+public:
+       CalDialogDetailCopyableItem();
+
+protected:
+       virtual void onCopySelected() = 0;
+       bool isSelecting();
+       void copyText(const char *text);
+
+private:
+       WDISABLE_COPY_AND_ASSIGN(CalDialogDetailCopyableItem);
+       virtual bool onLongpress() override;
+
+       void createPopup(Evas_Object *parent, const char *text, int x, int y);
+       void updateSelecting(bool isSelecting);
+
+       bool __isSelecting;
+};
+
+#endif
index 2c59ce1..235d6a2 100644 (file)
 #include "CalCommon.h"
 #include "CalDialogDetailDescriptionItem.h"
 
+#define TEXT_BUFFER_SIZE 1001
+#define TAG_BACKING "<backing=on><backing_color=#00ddff99>"
+
 CalDialogDetailDescriptionItem::CalDialogDetailDescriptionItem(const char *description)
+       : __description(g_strdup(description))
 {
-        __description = g_strdup(description);
 }
 
 CalDialogDetailDescriptionItem::~CalDialogDetailDescriptionItem()
@@ -41,6 +44,11 @@ Elm_Genlist_Item_Class *CalDialogDetailDescriptionItem::getItemClassStatic()
                        return g_strdup(_L_("IDS_CLD_BUTTON_NOTES_ABB"));
                else if (0 == strcmp(part, "elm.text.multiline")) {
                        CalDialogDetailDescriptionItem *item = (CalDialogDetailDescriptionItem*)data;
+                       if (item->isSelecting()) {
+                               char buffer[TEXT_BUFFER_SIZE];
+                               snprintf(buffer, sizeof(buffer), TAG_BACKING "%s", item->__description);
+                               return g_strdup(buffer);
+                       }
                        return g_strdup(item->__description);
                }
                return NULL;
@@ -48,3 +56,8 @@ Elm_Genlist_Item_Class *CalDialogDetailDescriptionItem::getItemClassStatic()
 
        return &itc;
 }
+
+void CalDialogDetailDescriptionItem::onCopySelected()
+{
+       CalDialogDetailCopyableItem::copyText(__description);
+}
index e391f74..f5cfb6d 100644 (file)
 #ifndef _CAL_DIALOG_DETAIL_DESCRIPTION_ITEM_H_
 #define _CAL_DIALOG_DETAIL_DESCRIPTION_ITEM_H_
 
-#include "CalDialogControl.h"
+#include "CalDialogDetailCopyableItem.h"
 
 /**
  * @brief Calendar dialog detail description item.
  *
- * @see CalDialogControl::Item
+ * @see CalDialogDetailCopyableItem
  */
-class CalDialogDetailDescriptionItem : public CalDialogControl::Item
+class CalDialogDetailDescriptionItem : public CalDialogDetailCopyableItem
 {
 public:
        /**
@@ -38,7 +38,8 @@ public:
 
 private:
        WDISABLE_COPY_AND_ASSIGN(CalDialogDetailDescriptionItem);
-       virtual Elm_Genlist_Item_Class *getItemClassStatic();
+       virtual Elm_Genlist_Item_Class* getItemClassStatic() override;
+       virtual void onCopySelected() override;
 
        char *__description;
 };
index eaf41c3..077150e 100644 (file)
@@ -21,6 +21,8 @@
 #include "CalDialogDetailLocationItem.h"
 
 #define DEFAULT_COLOR 0, 0, 0, 255
+#define TEXT_BUFFER_SIZE 1001
+#define TAG_BACKING "<backing=on><backing_color=#00ddff99>"
 
 CalDialogDetailLocationItem::CalDialogDetailLocationItem(const char *location)
        : __location(location)
@@ -41,6 +43,11 @@ Elm_Genlist_Item_Class *CalDialogDetailLocationItem::getItemClassStatic()
                if (0 == strcmp(part, "elm.text.title"))
                        return g_strdup(_L_("IDS_CLD_BUTTON_LOCATION_ABB"));
                if (0 == strcmp(part, "elm.text.multiline")) {
+                       if (item->isSelecting()) {
+                               char buffer[TEXT_BUFFER_SIZE];
+                               snprintf(buffer, sizeof(buffer), TAG_BACKING "%s", item->__location.c_str());
+                               return g_strdup(buffer);
+                       }
                        return g_strdup(item->__location.c_str());
                }
                return NULL;
@@ -49,3 +56,7 @@ Elm_Genlist_Item_Class *CalDialogDetailLocationItem::getItemClassStatic()
        return &itc;
 }
 
+void CalDialogDetailLocationItem::onCopySelected()
+{
+       CalDialogDetailCopyableItem::copyText(__location.c_str());
+}
index 3d0d663..fb4c0c6 100644 (file)
 #define _CAL_DIALOG_DETAIL_LOCATION_ITEM_H_
 
 #include <string>
-#include "CalDialogControl.h"
+#include "CalDialogDetailCopyableItem.h"
 
 /**
  * @brief Calendar dialog detail location item.
  *
- * @see CalDialogControl::Item
+ * @see CalDialogDetailCopyableItem
  */
-class CalDialogDetailLocationItem : public CalDialogControl::Item
+class CalDialogDetailLocationItem : public CalDialogDetailCopyableItem
 {
 public:
        /**
@@ -39,7 +39,8 @@ public:
 
 private:
        WDISABLE_COPY_AND_ASSIGN(CalDialogDetailLocationItem);
-       virtual Elm_Genlist_Item_Class *getItemClassStatic();
+       virtual Elm_Genlist_Item_Class* getItemClassStatic() override;
+       virtual void onCopySelected() override;
 
        std::string __location;
 };