--- /dev/null
+/*
+ * Copyright (c) 2015 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 UI_MENU_H
+#define UI_MENU_H
+
+#include "Ui/Control.h"
+#include <functional>
+
+namespace Ui
+{
+ class Menu : public Control
+ {
+ public:
+ /**
+ * @brief Item selection callback
+ */
+ typedef std::function<void()> ItemCallback;
+
+ /**
+ * @brief Add menu item
+ * @param[in] text Item text
+ * @param[in] callback Item selection callback
+ * @return Added item on success, otherwise nullptr
+ */
+ Elm_Object_Item *addItem(const char *text, ItemCallback callback);
+
+ protected:
+ virtual Evas_Object *onCreate(Evas_Object *parent) override;
+
+ private:
+ static void onItemSelect(void *data, Evas_Object *obj, void *item);
+ static void onItemDestroy(void *data, Evas_Object *obj, void *item);
+ void onDismissed(Evas_Object *obj, void *eventInfo);
+ };
+}
+
+#endif /* UI_MENU_H */
--- /dev/null
+/*
+ * Copyright (c) 2015 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 UI_POPUP_H
+#define UI_POPUP_H
+
+#include "Ui/Control.h"
+#include <functional>
+
+#define POPUP_BUTTON_MAX_COUNT 3
+
+namespace Ui
+{
+ class Popup : public Control
+ {
+ public:
+ /**
+ * @brief Popup button pressed callback
+ * @return true to destroy the Popup, otherwise false
+ */
+ typedef std::function<bool()> ButtonCallback;
+
+ Popup();
+
+ /**
+ * @brief Allows method overload instead of shadowing
+ */
+ using Control::create;
+
+ /**
+ * @brief Create popup with title, text and close button
+ * @param[in] parent Popup parent
+ * @param[in] title Popup title
+ * @param[in] text Popup text
+ * @param[in] button_text Text for close button
+ * @return Created popup
+ */
+ static Popup *create(Evas_Object *parent, const char *title,
+ const char *text, const char *button_text);
+
+ /**
+ * @brief Set Popup title
+ * @param[in] title Popup title
+ */
+ void setTitle(const char *title);
+
+ /**
+ * @brief Set Popup text
+ * @param[in] text Popup text
+ */
+ void setText(const char *text);
+
+ /**
+ * @brief Set Popup content
+ * @param[in] content Popup content
+ */
+ void setContent(Evas_Object *content);
+
+ /**
+ * @brief Add Popup button
+ * @param[in] text Button text
+ * @param[in] callback Button click callback
+ * @return Added button on success, otherwise nullptr
+ */
+ Evas_Object *addButton(const char *text, ButtonCallback callback = nullptr);
+
+ protected:
+ virtual Evas_Object *onCreate(Evas_Object *parent) override;
+
+ private:
+ void onButtonPressed(Evas_Object *obj, void *eventInfo);
+
+ ButtonCallback m_ButtonCbs[POPUP_BUTTON_MAX_COUNT];
+ size_t m_ButtonCount;
+ };
+}
+
+#endif /* UI_POPUP_H */
--- /dev/null
+/*
+ * Copyright (c) 2015 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 "Ui/Menu.h"
+#include "Utils/Callback.h"
+
+#include <efl_extension.h>
+
+using namespace Ui;
+
+Elm_Object_Item *Menu::addItem(const char *text, ItemCallback callback)
+{
+ Elm_Object_Item *item = elm_ctxpopup_item_append(getEvasObject(), text, nullptr,
+ &Menu::onItemSelect, new ItemCallback(std::move(callback)));
+ elm_object_item_text_translatable_set(item, EINA_TRUE);
+ elm_object_item_del_cb_set(item, &Menu::onItemDestroy);
+ return item;
+}
+
+Evas_Object *Menu::onCreate(Evas_Object *parent)
+{
+ Evas_Object *menu = elm_ctxpopup_add(parent);
+ elm_object_style_set(menu, "more/default");
+
+ evas_object_smart_callback_add(menu, "dismissed",
+ makeCallback(&Menu::onDismissed), this);
+ eext_object_event_callback_add(menu, EEXT_CALLBACK_BACK,
+ eext_ctxpopup_back_cb, nullptr);
+ eext_object_event_callback_add(menu, EEXT_CALLBACK_MORE,
+ eext_ctxpopup_back_cb, nullptr);
+
+ return menu;
+}
+
+void Menu::onItemSelect(void *data, Evas_Object *obj, void *item)
+{
+ ItemCallback &callback = *(ItemCallback *) data;
+ if (callback) {
+ callback();
+ }
+
+ elm_ctxpopup_dismiss(obj);
+}
+
+void Menu::onItemDestroy(void *data, Evas_Object *obj, void *item)
+{
+ delete (ItemCallback *) data;
+}
+
+void Menu::onDismissed(Evas_Object *obj, void *eventInfo)
+{
+ delete this;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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 "Ui/Popup.h"
+#include "Utils/Callback.h"
+
+#include <efl_extension.h>
+
+#define PART_POPUP_TITLE "title,text"
+
+using namespace Ui;
+
+namespace
+{
+ const char *buttonParts[POPUP_BUTTON_MAX_COUNT] = { "button1", "button2", "button3" };
+}
+
+Popup::Popup()
+ : m_ButtonCount(0)
+{
+}
+
+Popup *Popup::create(Evas_Object *parent, const char *title,
+ const char *text, const char *button_text)
+{
+ Popup *popup = new Popup();
+ popup->create(parent);
+ popup->setTitle(title);
+ popup->setText(text);
+ popup->addButton(button_text);
+ return popup;
+}
+
+void Popup::setTitle(const char *title)
+{
+ elm_object_domain_translatable_part_text_set(getEvasObject(), PART_POPUP_TITLE,
+ nullptr, title);
+}
+
+void Popup::setText(const char *text)
+{
+ elm_object_domain_translatable_text_set(getEvasObject(), nullptr, text);
+}
+
+void Popup::setContent(Evas_Object *content)
+{
+ elm_object_part_content_set(getEvasObject(), "elm.swallow.content", content);
+}
+
+Evas_Object *Popup::addButton(const char *text, ButtonCallback callback)
+{
+ if (m_ButtonCount >= POPUP_BUTTON_MAX_COUNT) {
+ return nullptr;
+ }
+
+ Evas_Object *button = elm_button_add(getEvasObject());
+ elm_object_style_set(button, "bottom");
+ elm_object_domain_translatable_text_set(button, nullptr, text);
+ elm_object_part_content_set(getEvasObject(), buttonParts[m_ButtonCount], button);
+
+ m_ButtonCbs[m_ButtonCount] = std::move(callback);
+ evas_object_smart_data_set(button, &m_ButtonCbs[m_ButtonCount]);
+ evas_object_smart_callback_add(button, "clicked",
+ makeCallback(&Popup::onButtonPressed), this);
+
+ ++m_ButtonCount;
+ return button;
+}
+
+Evas_Object *Popup::onCreate(Evas_Object *parent)
+{
+ Evas_Object *popup = elm_popup_add(parent);
+
+ elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
+ evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+
+ eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, nullptr);
+ evas_object_show(popup);
+
+ return popup;
+}
+
+void Popup::onButtonPressed(Evas_Object *obj, void *eventInfo)
+{
+ ButtonCallback &callback = *(ButtonCallback *) evas_object_smart_data_get(obj);
+ if (!callback || callback()) {
+ delete this;
+ }
+}