ui_menu is a interface for supporting menu feature.
normally, ui_view has one ui_menu and in mobile case, ui_menu is decoration of ctxpopup.
Change-Id: Ie725ed561666673e55bfce225d9987bc67a7ad63
../../lib/efl/ui_base_viewmgr.cpp
../../lib/efl/ui_base_key_listener.cpp
../../lib/efl/mobile/ui_controller.cpp
+ ../../lib/efl/mobile/ui_menu.cpp
../../lib/efl/mobile/ui_view.cpp
../../lib/efl/mobile/ui_key_listener.cpp
../../lib/efl/mobile/ui_viewmgr.cpp
view->set_content(content, "Title");
}
- bool on_menu()
+ void on_menu(ui_menu *menu)
{
- ui_view *view = dynamic_cast<ui_view *>(this->get_view());
-
- Elm_Ctxpopup *ctxpopup = elm_ctxpopup_add(view->get_base());
+ Elm_Ctxpopup *ctxpopup = elm_ctxpopup_add(menu->get_base());
elm_ctxpopup_item_append(ctxpopup, "Phone calls", NULL, ctxpopup_item_select_cb, this);
elm_ctxpopup_item_append(ctxpopup, "Favorites", NULL, ctxpopup_item_select_cb, this);
elm_ctxpopup_item_append(ctxpopup, "Search", NULL, ctxpopup_item_select_cb, this);
elm_ctxpopup_item_append(ctxpopup, "Search", NULL, ctxpopup_item_select_cb, this);
elm_ctxpopup_item_append(ctxpopup, "Dialer", NULL, ctxpopup_item_select_cb, this);
- view->set_menu(ctxpopup);
-
- return true;
+ menu->set_content(ctxpopup);
}
void on_rotate(int degree)
namespace efl_viewmgr
{
+class ui_menu;
+
class ui_controller: public ui_base_controller
{
public:
virtual ~ui_controller();
- virtual bool on_menu();
+ virtual void on_menu(ui_menu *menu);
};
}
}
-#endif /* UI_BASIC_KEY_HANDLER_H */
+#endif /* UI_KEY_HANDLER_H */
--- /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 UI_MENU_H
+#define UI_MENU_H
+
+#include "../ui_viewmanager_base.h"
+
+namespace efl_viewmgr
+{
+class ui_view;
+
+class ui_menu
+{
+ friend class ui_view;
+private:
+ ui_view *view;
+ Elm_Ctxpopup *ctxpopup;
+
+ ui_menu(ui_view *view);
+ virtual ~ui_menu();
+
+ Elm_Win *get_window();
+
+public:
+ virtual bool activate();
+ virtual bool deactivate();
+ virtual bool set_content(Elm_Ctxpopup* ctxpopup);
+ virtual Elm_Ctxpopup *unset_content();
+
+ virtual Elm_Ctxpopup *get_content()
+ {
+ return this->ctxpopup;
+ }
+
+ virtual bool is_activated();
+ virtual Evas_Object *get_base();
+};
+
+}
+
+#endif /* UI_MENU_H */
class ui_view: public ui_base_view
{
+ friend class ui_menu;
+ friend class ui_key_listener;
+
private:
Elm_Layout *layout; //Base layout for view
- Elm_Ctxpopup *ctxpopup; //Menu Widget
+ ui_menu *menu; //Menu
bool create_layout();
bool destroy_layout();
protected:
virtual void on_load();
virtual void on_unload();
+ virtual void on_menu();
virtual void unload_content();
virtual void set_event_block(bool block);
bool set_title_right_btn(Elm_Button *title_right_btn);
bool set_title(const char *text);
bool set_toolbar(Elm_Toolbar *toolbar);
- bool set_menu(Elm_Ctxpopup *menu);
- Elm_Ctxpopup *unset_menu();
Evas_Object *unset_content();
Elm_Button *unset_title_left_btn();
Elm_Button *unset_title_right_btn();
Elm_Toolbar *unset_toolbar();
- virtual void on_menu();
-
virtual Evas_Object *get_base()
{
if (!this->layout)this->create_layout();
return this->layout;
}
- Elm_Ctxpopup *get_menu()
+ const ui_menu *get_menu()
{
- return this->ctxpopup;
+ return this->menu;
}
};
#include "ui_view.h"
#include "ui_key_listener.h"
#include "ui_viewmgr.h"
+#include "ui_menu.h"
*/
virtual void on_destroy() {}
- /** @brief Back key callback.
- *
- * @note In default. current view will be popped by viewmgr in those scenarios
- * that viewmgr is requested to poo the current view.
- * If you return false in the overriding, then popping will be stopped.
- */
- virtual bool on_back() { return true; }
-
/** @brief View rotate callback.
*
* @param degree Current rotation degree.
* @note When current view is on landscape mode.
*/
virtual void on_landscape() {}
+
+ /** @brief Back key callback.
+ *
+ * @note In default. current view will be popped by viewmgr in those scenarios
+ * that viewmgr is requested to poo the current view.
+ * If you return false in the overriding, then popping will be stopped.
+ */
+ virtual bool on_back() { return true; }
+
};
}
*/
virtual void on_destroy() = 0;
- /** @brief Back key callback.
- *
- * @note In default. current view will be popped by viewmgr in those scenarios
- * that viewmgr is requested to poo the current view.
- * If you return false in the overriding, then popping will be stopped.
- */
- virtual bool on_back() = 0;
-
/** @brief View rotate callback.
*
* @param degree Current rotation degree.
efl/ui_base_viewmgr.cpp
efl/ui_base_key_listener.cpp
efl/mobile/ui_controller.cpp
+ efl/mobile/ui_menu.cpp
efl/mobile/ui_view.cpp
efl/mobile/ui_key_listener.cpp
efl/mobile/ui_viewmgr.cpp
{
}
-bool ui_controller::on_menu()
+void ui_controller::on_menu(ui_menu *menu)
{
- return true;
}
--- /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 "../../../include/efl/mobile/ui_viewmanager.h"
+
+using namespace efl_viewmgr;
+
+#define MY_VIEWMGR
+
+static void ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ evas_object_hide(obj);
+}
+
+static void ctxpopup_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ ui_menu *menu = static_cast<ui_menu *>(data);
+ menu->unset_content();
+}
+
+static bool update_menu(ui_menu *menu)
+{
+ Elm_Win *win = menu->get_base();
+ if (!win) return false;
+
+ Elm_Ctxpopup *ctxpopup = menu->get_content();
+ if (!ctxpopup) return false;
+
+ /* We convince the top widget is a window */
+ Evas_Coord w, h;
+ elm_win_screen_size_get(win, NULL, NULL, &w, &h);
+ int rot = elm_win_rotation_get(win);
+
+ switch (rot)
+ {
+ case 0:
+ case 180:
+ evas_object_move(ctxpopup, (w / 2), h);
+ break;
+ case 90:
+ case 270:
+ evas_object_move(ctxpopup, (h / 2), w);
+ break;
+ }
+
+ evas_object_show(ctxpopup);
+
+ return true;
+}
+
+static void win_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ ui_menu *menu = static_cast<ui_menu *>(data);
+ Elm_Ctxpopup *ctxpopup = menu->get_content();
+ if (!ctxpopup) return;
+ if (!evas_object_visible_get(ctxpopup)) return;
+ update_menu(menu);
+}
+
+ui_menu::ui_menu(ui_view *view)
+ : view(view), ctxpopup(NULL)
+{
+ Elm_Win *win = this->get_window();
+ evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, win_resize_cb, this);
+}
+
+ui_menu::~ui_menu()
+{
+ Elm_Win *win = this->get_window();
+ if (win) evas_object_event_callback_del(win, EVAS_CALLBACK_RESIZE, win_resize_cb);
+ evas_object_del(this->ctxpopup);
+}
+
+Elm_Win *ui_menu::get_window()
+{
+ ui_viewmgr *viewmgr = dynamic_cast<ui_viewmgr *>(this->view->get_viewmgr());
+ if (!viewmgr)
+ {
+ LOGE("Viewmgr is null?? menu(%p)", this);
+ return NULL;
+ }
+
+ return viewmgr->get_window();
+}
+
+bool ui_menu::deactivate()
+{
+ if (this->ctxpopup)
+ {
+ elm_ctxpopup_dismiss(this->ctxpopup);
+ }
+ else
+ {
+ LOGE("Content is not set! = ui_menu(%p)", this);
+ return false;
+ }
+
+ return true;
+}
+
+bool ui_menu::activate()
+{
+ return update_menu(this);
+}
+
+bool ui_menu::set_content(Elm_Ctxpopup *ctxpopup)
+{
+ evas_object_del(this->ctxpopup);
+
+ //validation!
+ //FIXME: isa ?
+ if (strcmp(evas_object_type_get(ctxpopup), "elm_ctxpopup"))
+ {
+ LOGE("Menu widget is not a ctxpopup!");
+ return false;
+ }
+
+ //FIXME: rename style.
+ elm_object_style_set(ctxpopup, "more/default");
+ elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
+ evas_object_smart_callback_add(ctxpopup, "dismissed", ctxpopup_dismissed_cb, NULL);
+ evas_object_event_callback_add(ctxpopup, EVAS_CALLBACK_DEL, ctxpopup_del_cb, this);
+
+ this->ctxpopup = ctxpopup;
+
+ return true;
+}
+
+bool ui_menu::is_activated()
+{
+ if (!this->ctxpopup) return false;
+ return evas_object_visible_get(this->ctxpopup);
+}
+
+Elm_Ctxpopup *ui_menu::unset_content()
+{
+ if (!this->ctxpopup) return NULL;
+
+ Elm_Ctxpopup *prev = this->ctxpopup;
+ this->ctxpopup = NULL;
+ evas_object_smart_callback_del(prev, "dismissed", ctxpopup_dismissed_cb);
+ evas_object_event_callback_del(prev, EVAS_CALLBACK_DEL, ctxpopup_del_cb);
+ return prev;
+}
+
+Evas_Object *ui_menu::get_base()
+{
+ if (!this->view)
+ {
+ LOGE("View is null?? menu(%p)", this);
+ return NULL;
+ }
+
+ return this->get_window();
+}
using namespace viewmgr;
#define MY_VIEWMGR dynamic_cast<ui_viewmgr *>(this->get_viewmgr())
-#define MY_CONTROLLER dynamic_cast<ui_controller *>(this->get_controller()))
-
-static void menu_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
-{
- evas_object_hide(obj);
-}
-
-static void menu_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
-{
- ui_view *view = static_cast<ui_view *>(data);
- view->unset_menu();
-}
-
-static void update_menu(Elm_Win *win, Elm_Ctxpopup *ctxpopup)
-{
- /* We convince the top widget is a window */
- Evas_Coord w, h;
- elm_win_screen_size_get(win, NULL, NULL, &w, &h);
- int rot = elm_win_rotation_get(win);
-
- switch (rot)
- {
- case 0:
- case 180:
- evas_object_move(ctxpopup, (w / 2), h);
- break;
- case 90:
- case 270:
- evas_object_move(ctxpopup, (h / 2), w);
- break;
- }
- evas_object_show(ctxpopup);
-}
+#define MY_CONTROLLER dynamic_cast<ui_controller *>(this->get_controller())
bool ui_view::destroy_layout()
{
}
}
- //FIXME: .... ?
- evas_object_event_callback_add(layout, EVAS_CALLBACK_RESIZE,
- [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
- {
- ui_view *view = static_cast<ui_view *>(data);
- Elm_Ctxpopup *ctxpopup = view->get_menu();
- if (ctxpopup && evas_object_visible_get(ctxpopup))
- {
- update_menu(dynamic_cast<ui_viewmgr *>(view->get_viewmgr())->get_window(), ctxpopup);
- }
- },
- this);
-
- evas_object_event_callback_add(layout, EVAS_CALLBACK_MOVE,
- [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
- {
- ui_view *view = static_cast<ui_view *>(data);
- Elm_Ctxpopup *ctxpopup = view->get_menu();
- if (ctxpopup && evas_object_visible_get(ctxpopup))
- {
- elm_ctxpopup_dismiss(ctxpopup);
- }
- },
- this);
-
this->layout = layout;
return true;
}
ui_view::ui_view(ui_controller *controller, const char *name)
- : ui_base_view(controller, name), layout(NULL), ctxpopup(NULL)
+ : ui_base_view(controller, name), layout(NULL), menu(NULL)
{
}
ui_view::~ui_view()
{
- evas_object_del(this->ctxpopup);
+ if (menu) delete(this->menu);
destroy_layout();
}
return pcontent;
}
-bool ui_view::set_menu(Elm_Ctxpopup *menu)
-{
- if (this->ctxpopup) evas_object_del(this->ctxpopup);
-
- //validation!
- if (strcmp(evas_object_type_get(menu), "elm_ctxpopup"))
- {
- LOGE("Menu widget is not a ctxpopup!");
- return false;
- }
-
- //FIXME: rename style.
- elm_object_style_set(menu, "more/default");
- elm_ctxpopup_auto_hide_disabled_set(menu, EINA_TRUE);
- evas_object_smart_callback_add(menu, "dismissed", menu_dismissed_cb, NULL);
- evas_object_event_callback_add(menu, EVAS_CALLBACK_DEL, menu_del_cb, this);
-
- this->ctxpopup = menu;
-
- return true;
-}
-
bool ui_view::set_toolbar(Elm_Toolbar *toolbar)
{
Elm_Layout *layout = this->get_base();
void ui_view::on_menu()
{
- if (this->ctxpopup && evas_object_visible_get(this->ctxpopup))
+ if (this->menu && this->menu->is_activated())
{
- elm_ctxpopup_dismiss(this->ctxpopup);
+ this->menu->deactivate();
return;
}
if (this->get_controller())
{
- (MY_CONTROLLER->on_menu();
+ if (!this->menu)
+ {
+ this->menu = new ui_menu(this);
+ }
+ MY_CONTROLLER->on_menu(this->menu);
}
- if (this->ctxpopup)
+ if (this->menu && this->menu->get_content())
{
- update_menu(MY_VIEWMGR->get_window(), this->ctxpopup);
+ this->menu->activate();
}
}
evas_object_freeze_events_set(this->get_base(), block);
}
-Elm_Ctxpopup* ui_view::unset_menu()
-{
- Elm_Ctxpopup *menu = this->ctxpopup;
- evas_object_event_callback_del(menu, EVAS_CALLBACK_DEL, menu_del_cb);
- evas_object_smart_callback_del(menu, "dismissed", menu_dismissed_cb);
- this->ctxpopup = NULL;
- return menu;
-}
-
Evas_Object *ui_view::unset_content()
{
Evas_Object *pcontent = ui_base_view::unset_content();
if (strcmp(ev->keyname, KEY_BACK) && strcmp(ev->keyname, KEY_BACK2)) return;
+ //FIXME: cancel menu??
view->on_back();
}