introduce ui_menu for menu feature. 01/63401/1
authorHermet Park <hermet@hermet.pe.kr>
Wed, 23 Mar 2016 13:19:26 +0000 (22:19 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Wed, 23 Mar 2016 13:19:47 +0000 (22:19 +0900)
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

14 files changed:
src/examples/efl/CMakeLists.txt
src/examples/efl/page1.h
src/include/efl/mobile/ui_controller.h
src/include/efl/mobile/ui_key_listener.h
src/include/efl/mobile/ui_menu.h [new file with mode: 0644]
src/include/efl/mobile/ui_view.h
src/include/efl/mobile/ui_viewmanager.h
src/include/efl/ui_base_controller.h
src/include/interface/ui_iface_controller.h
src/lib/CMakeLists.txt
src/lib/efl/mobile/ui_controller.cpp
src/lib/efl/mobile/ui_menu.cpp [new file with mode: 0644]
src/lib/efl/mobile/ui_view.cpp
src/lib/efl/ui_base_key_listener.cpp

index 89278af99882d71b4ca4f88284b12c6726e1d3cf..319eadbfb2f5dd8ed35c9c6b4a79d5cfdcce0b98 100644 (file)
@@ -8,6 +8,7 @@ SET(EXAM_SRCS
          ../../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
index 8074916c54d56707533591ac3d7d94d1417af1ad..f31c8600db6e9f3f8bc7b4e37c0956f7ddfc36cd 100644 (file)
@@ -67,11 +67,9 @@ public:
                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);
@@ -82,9 +80,7 @@ public:
                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)
index 0ac055abada53abb1b9873ec8ace6ec688badf20..6260473717b2ec930a218709175b4d9b40895aaf 100644 (file)
 
 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);
 };
 }
 
index 4410870cff8a742dfdecab9b40b4fb44778795e5..927007ec019e6288ad7168e5589abe04f17117bd 100644 (file)
@@ -34,4 +34,4 @@ public:
 
 }
 
-#endif /* UI_BASIC_KEY_HANDLER_H */
+#endif /* UI_KEY_HANDLER_H */
diff --git a/src/include/efl/mobile/ui_menu.h b/src/include/efl/mobile/ui_menu.h
new file mode 100644 (file)
index 0000000..0982280
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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 */
index 36828ac1c3c89e4719452437f7e438fb7d3c1809..9941228ab7f0afe64c4c9fc2067ac7dbbbd8a9b5 100644 (file)
@@ -24,9 +24,12 @@ namespace efl_viewmgr
 
 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();
@@ -34,6 +37,7 @@ private:
 protected:
        virtual void on_load();
        virtual void on_unload();
+       virtual void on_menu();
        virtual void unload_content();
        virtual void set_event_block(bool block);
 
@@ -50,24 +54,20 @@ public:
        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;
        }
 
 };
index 56b1fad461e32ae9025d18fefb2b030bf608a004..dc2f7d1f206e202593a8c650dca74ee1498a7b8d 100644 (file)
@@ -25,3 +25,4 @@
 #include "ui_view.h"
 #include "ui_key_listener.h"
 #include "ui_viewmgr.h"
+#include "ui_menu.h"
index d72491fc9548d785ba68875a752890a4c85c94ab..dcf3d483c11992725720d282a31e5aecbaff7edc 100644 (file)
@@ -103,14 +103,6 @@ public:
         */
        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.
@@ -130,6 +122,15 @@ public:
         *  @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; }
+
 };
 }
 
index a2e619961be486cb45cdfd469196b1f268190363..0fa7caadd09ad9f7602794d2ce8b1e9aaa69e315 100644 (file)
@@ -121,14 +121,6 @@ public:
         */
        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.
index 5be1b727b3203e673d2d94d82d6f904682dd517a..01631731394cc4eaf0b30491ca87d2d3b2924956 100644 (file)
@@ -7,6 +7,7 @@ SET(LIB_SRCS
      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
index d5ab72d567e0d25cd892724ca9e20524995203bc..7bff68983383e4b6b58d27ceacb13b7446a6c215 100644 (file)
@@ -23,7 +23,6 @@ ui_controller::~ui_controller()
 {
 }
 
-bool ui_controller::on_menu()
+void ui_controller::on_menu(ui_menu *menu)
 {
-       return true;
 }
diff --git a/src/lib/efl/mobile/ui_menu.cpp b/src/lib/efl/mobile/ui_menu.cpp
new file mode 100644 (file)
index 0000000..1878b48
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * 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();
+}
index fe0380a4e89b5398e3f81ca06f496baf77fd5427..db07c9eea7a69526733c4300b5b979c116dbcba4 100644 (file)
@@ -24,39 +24,7 @@ using namespace efl_viewmgr;
 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()
 {
@@ -117,38 +85,13 @@ bool ui_view::create_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)
 {
 }
 
@@ -159,7 +102,7 @@ ui_view::ui_view(const char *name)
 
 ui_view::~ui_view()
 {
-       evas_object_del(this->ctxpopup);
+       if (menu) delete(this->menu);
        destroy_layout();
 }
 
@@ -286,28 +229,6 @@ Evas_Object *ui_view::set_content(Evas_Object *content, const char *title, const
        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();
@@ -349,20 +270,24 @@ void ui_view::unload_content()
 
 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();
        }
 }
 
@@ -372,15 +297,6 @@ void ui_view::set_event_block(bool block)
        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();
index 3a2bd92d3f2126ffea0226a636c6e4c4a089a872..8abefd8c5d1f118cb62e42789d0c37047664c379 100644 (file)
@@ -42,6 +42,7 @@ static void event_proc(ui_base_key_listener *key_listener, Evas_Event_Key_Down *
 
        if (strcmp(ev->keyname, KEY_BACK) && strcmp(ev->keyname, KEY_BACK2)) return;
 
+       //FIXME: cancel menu??
        view->on_back();
 }