namespace Ui
{
+ class View;
+
class EXPORT_API Hoversel : public Selector
{
public:
+ Hoversel();
+ virtual ~Hoversel() override;
+
/**
* @brief Add item with text.
* @param[in] text Item text
virtual Evas_Object *onCreate(Evas_Object *parent) override;
private:
+ void onViewNavigation(Evas_Object *obj, void *eventInfo);
void onSelected(Evas_Object *hoversel, Elm_Object_Item *item);
static void onExpanded(void *data, Evas_Object *hoversel, void *eventInfo);
static void onDismissed(void *data, Evas_Object *hoversel, void *eventInfo);
static void onBackPressed(void *data, Evas_Object *hoversel, void *eventInfo);
+
+ View *m_View;
};
}
namespace Ui
{
+ class View;
+ class Window;
+
class EXPORT_API Menu : public Control
{
public:
*/
typedef std::function<void()> ItemCallback;
+ Menu();
+ virtual ~Menu() override;
+
/**
* @brief Add menu item
* @param[in] text Item text
virtual Evas_Object *onCreate(Evas_Object *parent) override;
private:
+ void onViewNavigation(Evas_Object *obj, void *eventInfo);
+ void onWindowResized(Evas *e, Evas_Object *obj, void *eventInfo);
+
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);
+
+ View *m_View;
+ Window *m_Window;
};
}
namespace Ui
{
+ class View;
+ class Window;
+
class EXPORT_API Popup : public Control
{
public:
typedef std::function<bool()> ButtonCallback;
Popup();
+ virtual ~Popup() override;
/**
* @brief Allows method overload instead of shadowing.
private:
void onCanceled();
+
+ void onViewNavigation(Evas_Object *obj, void *eventInfo);
+ void onViewDestroy(Evas *e, Evas_Object *obj, void *eventInfo);
+
void onButtonPressed(Evas_Object *obj, void *eventInfo);
void onButtonDestroy(Evas *e, Evas_Object *obj, void *eventInfo);
void onBackPressed(Evas_Object *obj, void *eventInfo);
size_t m_ButtonCount;
ButtonCallback m_OnCanceled;
+
+ View *m_View;
+ Window *m_Window;
};
}
#include "Ui/Control.h"
#include "Ui/NavigatorPage.h"
+#define EVENT_VIEW_NAVIGATION "navigation"
+
namespace Ui
{
class Navigator;
*/
#include "Ui/Hoversel.h"
+#include "Ui/View.h"
#include "Ui/Window.h"
#include "Utils/Callback.h"
using namespace Ui;
+Hoversel::Hoversel()
+ : m_View(nullptr)
+{
+}
+
+Hoversel::~Hoversel()
+{
+ if (m_View) {
+ evas_object_smart_callback_del_full(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+ makeCallback(&Hoversel::onViewNavigation), this);
+ }
+}
+
Elm_Object_Item *Hoversel::addItem(const char *text, void *data)
{
Elm_Object_Item *item = elm_hoversel_item_add(getEvasObject(), text,
Evas_Object *Hoversel::onCreate(Evas_Object *parent)
{
- Evas_Object *hoverParent = parent;
- Window *window = findParent<Window>(parent);
- if (window) {
- hoverParent = window->getBaseLayout();
- }
-
Evas_Object *hoversel = elm_hoversel_add(parent);
- elm_hoversel_hover_parent_set(hoversel, hoverParent);
-
evas_object_smart_callback_add(hoversel, "selected",
(Evas_Smart_Cb) makeCallback(&Hoversel::onSelected), this);
evas_object_smart_callback_add(hoversel, "expanded",
evas_object_smart_callback_add(hoversel, "dismissed",
&Hoversel::onDismissed, this);
+ m_View = findParent<View>(parent);
+ if (m_View) {
+ evas_object_smart_callback_add(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+ makeCallback(&Hoversel::onViewNavigation), this);
+ }
+
+ auto window = findParent<Window>(parent);
+ if (window) {
+ elm_hoversel_hover_parent_set(hoversel, window->getEvasObject());
+ }
+
return hoversel;
}
+void Hoversel::onViewNavigation(Evas_Object *obj, void *eventInfo)
+{
+ if (!eventInfo) {
+ elm_hoversel_hover_end(getEvasObject());
+ }
+}
+
void Hoversel::onSelected(Evas_Object *hoversel, Elm_Object_Item *item)
{
if (Selector::onSelected(item)) {
*/
#include "Ui/Menu.h"
+#include "Ui/View.h"
#include "Ui/Window.h"
#include "Utils/Callback.h"
using namespace Ui;
+Menu::Menu()
+ : m_View(nullptr), m_Window(nullptr)
+{
+}
+
+Menu::~Menu()
+{
+ if (m_View) {
+ evas_object_smart_callback_del_full(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+ makeCallback(&Menu::onViewNavigation), this);
+ }
+ if (m_Window) {
+ evas_object_event_callback_del_full(m_Window->getEvasObject(), EVAS_CALLBACK_RESIZE,
+ makeCallback(&Menu::onWindowResized), this);
+ }
+}
+
Elm_Object_Item *Menu::addItem(const char *text, ItemCallback callback)
{
Elm_Object_Item *item = elm_ctxpopup_item_append(getEvasObject(), text, nullptr,
void Menu::show()
{
- Window *window = findParent<Window>();
- if (!window) {
- return;
- }
-
- Evas_Coord y = 0, h = 0;
- evas_object_geometry_get(window->getEvasObject(), nullptr, &y, nullptr, &h);
+ Evas_Coord y = 0, w = 0, h = 0;
+ Evas_Object *parent = elm_ctxpopup_hover_parent_get(getEvasObject());
+ evas_object_geometry_get(parent, nullptr, &y, &w, &h);
Evas_Object *menu = getEvasObject();
- evas_object_move(menu, 0, y + h);
+ int menuWidth = 0;
+ evas_object_geometry_get(menu, nullptr, nullptr, &menuWidth, nullptr);
+ evas_object_move(menu, w / 2 - menuWidth / 2, y + h);
evas_object_show(menu);
}
Evas_Object *Menu::onCreate(Evas_Object *parent)
{
- Window *window = findParent<Window>(parent);
- if (window) {
- parent = window->getEvasObject();
- }
-
Evas_Object *menu = elm_ctxpopup_add(parent);
elm_object_style_set(menu, "more/default");
eext_object_event_callback_add(menu, EEXT_CALLBACK_MORE,
eext_ctxpopup_back_cb, nullptr);
+ m_View = findParent<View>(parent);
+ if (m_View) {
+ evas_object_smart_callback_add(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+ makeCallback(&Menu::onViewNavigation), this);
+ }
+
+ m_Window = findParent<Window>(parent);
+ if (m_Window) {
+ elm_ctxpopup_hover_parent_set(menu, m_Window->getEvasObject());
+ evas_object_event_callback_add(m_Window->getEvasObject(), EVAS_CALLBACK_RESIZE,
+ makeCallback(&Menu::onWindowResized), this);
+ }
+
return menu;
}
+void Menu::onViewNavigation(Evas_Object *obj, void *eventInfo)
+{
+ if (!eventInfo) {
+ elm_ctxpopup_dismiss(getEvasObject());
+ }
+}
+
+void Menu::onWindowResized(Evas *e, Evas_Object *obj, void *eventInfo)
+{
+ show();
+}
+
void Menu::onItemSelect(void *data, Evas_Object *obj, void *item)
{
ItemCallback &callback = *(ItemCallback *) data;
*/
#include "Ui/Popup.h"
+#include "Ui/View.h"
#include "Ui/Window.h"
#include "Utils/Callback.h"
#include "Utils/Range.h"
using namespace Ui;
Popup::Popup()
- : m_ButtonCount(0)
+ : m_ButtonCount(0), m_View(nullptr), m_Window(nullptr)
{
}
+Popup::~Popup()
+{
+ if (m_View) {
+ evas_object_smart_callback_del_full(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+ makeCallback(&Popup::onViewNavigation), this);
+ evas_object_event_callback_del_full(m_View->getEvasObject(), EVAS_CALLBACK_DEL,
+ makeCallback(&Popup::onViewDestroy), this);
+ }
+}
+
Popup *Popup::create(Evas_Object *parent, const char *title,
const char *text, const char *buttonText)
{
Evas_Object *Popup::onCreate(Evas_Object *parent)
{
- Window *window = findParent<Window>(parent);
- if (window) {
- parent = window->getBaseLayout();
+ m_View = findParent<View>(parent);
+ if (m_View) {
+ evas_object_smart_callback_add(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+ makeCallback(&Popup::onViewNavigation), this);
+ evas_object_event_callback_add(m_View->getEvasObject(), EVAS_CALLBACK_DEL,
+ makeCallback(&Popup::onViewDestroy), this);
+ }
+
+ m_Window = findParent<Window>(parent);
+ if (m_Window) {
+ parent = m_Window->getBaseLayout();
}
Evas_Object *popup = elm_popup_add(parent);
}
}
+void Popup::onViewNavigation(Evas_Object *obj, void *eventInfo)
+{
+ if (!eventInfo) {
+ /* Don't close the popup if navigation is caused by window losing focus */
+ if (!m_Window || elm_win_focus_get(m_Window->getEvasObject())) {
+ onCanceled();
+ }
+ }
+}
+
+void Popup::onViewDestroy(Evas *e, Evas_Object *obj, void *eventInfo)
+{
+ m_View = nullptr;
+}
+
void Popup::onButtonPressed(Evas_Object *obj, void *eventInfo)
{
ButtonCallback *callback = (ButtonCallback *) evas_object_data_get(obj, BUTTON_DATA_KEY);
ecore_timer_freeze(m_ShowMinTimer);
setCancelCallback([this] {
- return m_IsDestroyPending;
+ return false;
});
}
}
onNavigation(m_IsCurrent);
+ evas_object_smart_callback_call(getEvasObject(), EVENT_VIEW_NAVIGATION, (void *) (long) m_IsCurrent);
}
void View::onRotation(int degree)