#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)
{
}
return fontSize;
}
+void CalDialogControl::Item::onLongpressed()
+{
+ __isLongpressed = onLongpress();
+}
+
+void CalDialogControl::Item::onSelected()
+{
+ if (__isLongpressed) {
+ __isLongpressed = false;
+ return;
+ }
+ onSelect();
+}
+
CalDialogControl::CalDialogControl()
{
WENTER();
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();
elm_genlist_item_selected_set(genlistItem, EINA_FALSE);
CalDialogControl::Item* item = (CalDialogControl::Item*)data;
- item->onSelect();
+ item->onSelected();
WHIT();
}, item);
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.
bool __isGroupTitle;
private:
+ void onSelected();
+ void onLongpressed();
+
int __sortIndex;
- void* __customData;
+ void *__customData;
+ bool __isLongpressed;
friend class CalDialogControl;
};
__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
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);
- }
}
}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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
#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()
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;
return &itc;
}
+
+void CalDialogDetailDescriptionItem::onCopySelected()
+{
+ CalDialogDetailCopyableItem::copyText(__description);
+}
#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:
/**
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;
};
#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)
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;
return &itc;
}
+void CalDialogDetailLocationItem::onCopySelected()
+{
+ CalDialogDetailCopyableItem::copyText(__location.c_str());
+}
#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:
/**
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;
};