ui_viewmgr: change to singleton instance and update examples. 50/64050/2
authorHermet Park <hermet@hermet.pe.kr>
Tue, 29 Mar 2016 14:20:53 +0000 (23:20 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Wed, 30 Mar 2016 09:18:22 +0000 (18:18 +0900)
Conflicts:
src/examples/efl/page14.h
src/examples/efl/page15.h

Change-Id: I6fdc86f7ffa0708d6b6b526a27ad047a3e15b8d8

33 files changed:
src/examples/efl/main.cpp
src/examples/efl/main.h
src/examples/efl/page1.h
src/examples/efl/page10.h
src/examples/efl/page11.h
src/examples/efl/page12.h
src/examples/efl/page13.h
src/examples/efl/page14.h
src/examples/efl/page15.h
src/examples/efl/page2.h
src/examples/efl/page3.h
src/examples/efl/page4.h
src/examples/efl/page5.h
src/examples/efl/page6.h
src/examples/efl/page7.h
src/examples/efl/page8.h
src/examples/efl/page9.h
src/include/efl/mobile/ui_controller.h
src/include/efl/mobile/ui_view.h
src/include/efl/mobile/ui_viewmanager.h
src/include/efl/mobile/ui_viewmgr.h
src/include/efl/ui_base_controller.h
src/include/efl/ui_base_singleton.h [new file with mode: 0644]
src/include/efl/ui_base_viewmgr.h
src/include/efl/ui_viewmanager_base.h
src/include/interface/ui_iface_controller.h
src/include/interface/ui_iface_view.h
src/lib/efl/mobile/ui_key_listener.cpp
src/lib/efl/mobile/ui_menu.cpp
src/lib/efl/mobile/ui_view.cpp
src/lib/efl/ui_base_popup.cpp
src/lib/efl/ui_base_view.cpp
src/lib/efl/ui_base_viewmgr.cpp

index f97ac27..143497a 100644 (file)
@@ -54,7 +54,7 @@ create_toolbar(Evas_Object *parent, const char *style)
 }
 
 Evas_Object*
-create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad)
+create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb)
 {
        char buf[128];
        Elm_Grid *grid;
@@ -103,7 +103,7 @@ create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb pr
        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0);
        elm_object_text_set(btn, "Prev");
-       evas_object_smart_callback_add(btn, "clicked", prev_btn_clicked_cb, ad);
+       evas_object_smart_callback_add(btn, "clicked", prev_btn_clicked_cb, NULL);
        evas_object_show(btn);
        elm_box_pack_end(box, btn);
 
@@ -112,7 +112,7 @@ create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb pr
        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0);
        elm_object_text_set(btn, "Next");
-       evas_object_smart_callback_add(btn, "clicked", next_btn_clicked_cb, ad);
+       evas_object_smart_callback_add(btn, "clicked", next_btn_clicked_cb, NULL);
        evas_object_show(btn);
        elm_box_pack_end(box, btn);
 
@@ -122,7 +122,7 @@ create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb pr
 }
 
 Evas_Object*
-create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad)
+create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb)
 {
        Elm_Grid *grid;
        Elm_Box *box;
@@ -162,7 +162,7 @@ create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_cli
        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0);
        elm_object_text_set(btn, "Prev");
-       evas_object_smart_callback_add(btn, "clicked", prev_btn_clicked_cb, ad);
+       evas_object_smart_callback_add(btn, "clicked", prev_btn_clicked_cb, NULL);
        evas_object_show(btn);
        elm_box_pack_end(box, btn);
 
@@ -171,7 +171,7 @@ create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_cli
        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, 1.0);
        elm_object_text_set(btn, "Next");
-       evas_object_smart_callback_add(btn, "clicked", next_btn_clicked_cb, ad);
+       evas_object_smart_callback_add(btn, "clicked", next_btn_clicked_cb, NULL);
        evas_object_show(btn);
        elm_box_pack_end(box, btn);
 
@@ -182,12 +182,8 @@ create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_cli
 
 static void create_base_gui(appdata_s *ad)
 {
-       //FIXME: Hide this creation.
-       ad->viewmgr = new ui_viewmgr(PACKAGE);
-
-       create_page1(ad);
-
-       ad->viewmgr->activate();
+       create_page1();
+       UI_VIEWMGR->activate();
 }
 
 int
@@ -196,6 +192,10 @@ elm_main(int argc, char **argv)
        appdata_s *ad = {0,};
 
        ad = static_cast<appdata_s *>(calloc(1, sizeof(appdata_s)));
+
+       //FIXME: Hide this creation.
+       ui_viewmgr *viewmgr = new ui_viewmgr(PACKAGE);
+
        create_base_gui(ad);
 
        elm_run();
index abc7ac7..321bc69 100644 (file)
@@ -39,6 +39,6 @@ typedef struct appdata {
        ui_viewmgr *viewmgr;
 } appdata_s;
 
-Evas_Object *create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad);
-Evas_Object *create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad);
+Evas_Object *create_landscape_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb);
+Evas_Object *create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb);
 Elm_Toolbar *create_toolbar(Evas_Object *parent, const char *style);
index 5ce77b3..5a0e4e3 100644 (file)
@@ -20,9 +20,6 @@
  */
 class page1: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -31,32 +28,23 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->deactivate();
+                                       UI_VIEWMGR->deactivate();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page2(ad);
-                               },
-                               this->ad);
-
+                                       create_page2();
+                               });
                this->set_content(content, "Title");
        }
 
 public:
-       page1(appdata_s *ad) : ui_view("page1"), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page1()
-       {
-       }
+       page1() : ui_view("page1") {}
+       ~page1() {}
 };
 
-void create_page1(appdata_s *ad)
+void create_page1()
 {
-       new page1(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page1());
 }
index e3be5ed..9dadddd 100644 (file)
@@ -21,9 +21,6 @@
  */
 class page10: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -38,18 +35,15 @@ protected:
        {
                Evas_Object *content = create_content(this->get_base(), "ViewMgr Demo<br>Page 10<br>(Portrait + Landscape)",
                        //Prev Button Callback
-                       [](void *data, Evas_Object *obj, void *event_info) -> void
-                       {
-                       appdata_s *ad = static_cast<appdata_s *>(data);
-                       ad->viewmgr->pop_view();
-                       },
-                       //Next Button Callback
-                       [](void *data, Evas_Object *obj, void *event_info) -> void
-                       {
-                       appdata_s *ad = static_cast<appdata_s *>(data);
-                       create_page11(ad);
-                       },
-                       this->ad);
+                               [](void *data, Evas_Object *obj, void *event_info) -> void
+                               {
+                                       UI_VIEWMGR->pop_view();
+                               },
+                               //Next Button Callback
+                               [](void *data, Evas_Object *obj, void *event_info) -> void
+                               {
+                                       create_page11();
+                       });
                this->set_content(content, "Title");
                this->set_indicator(UI_VIEW_INDICATOR_DEFAULT);
        }
@@ -58,34 +52,26 @@ protected:
        {
                Evas_Object *content = create_landscape_content(this->get_base(), "ViewMgr Demo<br>Page 10<br>(Portrait + Landscape)",
                                //Prev Button Callback
-                       [](void *data, Evas_Object *obj, void *event_info) -> void
-                       {
-                               appdata_s *ad = static_cast<appdata_s *>(data);
-                               ad->viewmgr->pop_view();
-                       },
-                       //Next Button Callback
-                       [](void *data, Evas_Object *obj, void *event_info) -> void
-                       {
-                               appdata_s *ad = static_cast<appdata_s *>(data);
-                               create_page11(ad);
-                       },
-                       this->ad);
+                               [](void *data, Evas_Object *obj, void *event_info) -> void
+                               {
+                                       UI_VIEWMGR->pop_view();
+                               },
+                               //Next Button Callback
+                               [](void *data, Evas_Object *obj, void *event_info) -> void
+                               {
+                                       create_page11();
+                               });
                this->set_content(content, "Title");
                this->set_indicator(UI_VIEW_INDICATOR_OPTIMAL);
        }
 
 public:
-       page10(appdata_s *ad) : ui_view("page10"), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page10()
-       {
-       }
+       page10() : ui_view("page10") {}
+       ~page10() {}
 };
 
-void create_page10(appdata_s *ad)
+void create_page10()
 {
-       new page10(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page10());
 }
index 9a5ed79..9312359 100644 (file)
  */
 class page11: public ui_controller
 {
-private:
-       appdata_s *ad;
-
-public:
-       page11(appdata_s *ad)
-                       : ad(ad)
-       {
-               ad->viewmgr->push_view(new ui_view(this, "page11"));
-       }
-
-       ~page11()
-       {
-       }
-
+protected:
        void on_load()
        {
                ui_view *view = dynamic_cast<ui_view *>(this->get_view());
-
                this->on_rotate(view->get_degree());
        }
 
@@ -51,18 +37,15 @@ public:
                {
                        Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 11<br>(Rotate)",
                                        //Prev Button Callback
-                               [](void *data, Evas_Object *obj, void *event_info) -> void
-                               {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
-                               },
-                               //Next Button Callback
-                               [](void *data, Evas_Object *obj, void *event_info) -> void
-                               {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page12(ad);
-                               },
-                               this->ad);
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               UI_VIEWMGR->pop_view();
+                                       },
+                                       //Next Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               create_page12();
+                                       });
                        view->set_content(content, "Title");
                        view->set_indicator(UI_VIEW_INDICATOR_DEFAULT);
                }
@@ -71,26 +54,29 @@ public:
                {
                        Evas_Object *content = create_landscape_content(view->get_base(), "ViewMgr Demo<br>Page 11<br>(Rotate)",
                                        //Prev Button Callback
-                               [](void *data, Evas_Object *obj, void *event_info) -> void
-                               {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
-                               },
-                               //Next Button Callback
-                               [](void *data, Evas_Object *obj, void *event_info) -> void
-                               {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page12(ad);
-                               },
-                               this->ad);
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               UI_VIEWMGR->pop_view();
+                                       },
+                                       //Next Button Callback
+                                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                                       {
+                                               create_page12();
+                                       });
                        view->set_content(content, "Title");
                        view->set_indicator(UI_VIEW_INDICATOR_OPTIMAL);
                }
        }
-
+public:
+       page11()
+       {
+               UI_VIEWMGR->push_view(new ui_view(this, "page11"));
+       }
+       ~page11() {}
 };
 
-void create_page11(appdata_s *ad)
+void create_page11()
 {
-       new page11(ad);
+       //page 11 controller
+       page11 *controller = new page11();
 }
index 2f8fff3..c65c976 100644 (file)
@@ -28,45 +28,25 @@ static void ctxpopup_item_select_cb(void *data, Evas_Object *obj, void *event_in
        LOGE("Item (%s) is selected", elm_object_item_text_get(it));
 }
 
-class page12: public ui_controller
+class page12: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
-               //Initialize contents.
-               ui_view *view = dynamic_cast<ui_view *>(this->get_view());
-
                //Create a main content.
-               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 12<br>(Menu Popup)",
+               Evas_Object *content = create_content(this->get_base(), "ViewMgr Demo<br>Page 12<br>(Menu Popup)",
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page13(ad);
-                               },
-                               this->ad);
-
-               view->set_content(content, "Title");
-       }
-
-public:
-       page12(appdata_s *ad)
-                       : ad(ad)
-       {
-               ad->viewmgr->push_view(new ui_view(this, "page12"));
-       }
+                                       create_page13();
+                               });
 
-       ~page12()
-       {
+               this->set_content(content, "Title");
        }
 
        void on_menu(ui_menu *menu)
@@ -84,9 +64,14 @@ public:
 
                menu->set_content(ctxpopup);
        }
+
+public:
+       page12() {}
+       ~page12() {}
 };
 
-void create_page12(appdata_s *ad)
+void create_page12()
 {
-       new page12(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page12());
 }
index c9e0db1..27e940b 100644 (file)
@@ -31,9 +31,6 @@ static void popup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
 
 class page13: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -42,16 +39,14 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page14(ad);
-                               },
-                               this->ad);
+                                       create_page14();
+                               });
+
                this->set_content(content, "Title");
 
                //Title Right button
@@ -68,15 +63,8 @@ protected:
        }
 
 public:
-       page13(const char *name, appdata_s *ad)
-                       : ui_view(name), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page13()
-       {
-       }
+       page13() : ui_view("page13") {}
+       ~page13() {}
 
        void create_popup()
        {
@@ -104,7 +92,8 @@ public:
        }
 };
 
-void create_page13(appdata_s *ad)
+void create_page13()
 {
-       new page13("page13", ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page13());
 }
index 6a15217..3003dc8 100644 (file)
@@ -20,9 +20,6 @@
  */
 class page14: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -31,33 +28,27 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page15(ad);
-                               },
-                               this->ad);
+                                       create_page15();
+                               });
 
                this->set_content(content, "Title");
        }
 
 public:
-       page14(appdata_s *ad) : ui_view("page14"), ad(ad)
+       page14() : ui_view("page14")
        {
                this->set_transition_style("blend");
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page14()
-       {
        }
+       ~page14() {}
 };
 
-void create_page14(appdata_s *ad)
+void create_page14()
 {
-       new page14(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page14());
 }
index b4e32a5..2cbf09a 100644 (file)
@@ -20,9 +20,6 @@
  */
 class page15: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -31,33 +28,27 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->deactivate();
-                               },
-                               this->ad);
+                                       UI_VIEWMGR->deactivate();
+                               });
 
                this->set_content(content, "Title");
        }
 
 public:
-       page15(appdata_s *ad) : ui_view("page15"), ad(ad)
+       page15() : ui_view("page15")
        {
                this->set_transition_style("none");
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page15()
-       {
        }
+       ~page15(){}
 };
 
-void create_page15(appdata_s *ad)
+void create_page15()
 {
-       new page15(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page15());
 }
index d5def0d..dd3986c 100644 (file)
  */
 class page2: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
                //Create a main content.
                Evas_Object *content = create_content(this->get_base(), "ViewMgr Demo<br>Page 2",
-                               //Prev Button Callback
-                               [](void *data, Evas_Object *obj, void *event_info) -> void
-                               {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
-                               },
-                               //Next Button Callback
-                               [](void *data, Evas_Object *obj, void *event_info) -> void
-                               {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page3(ad);
-                               },
-                               this->ad);
+               //Prev Button Callback
+                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                       {
+                               UI_VIEWMGR->pop_view();
+                       },
+                       //Next Button Callback
+                       [](void *data, Evas_Object *obj, void *event_info) -> void
+                       {
+                               create_page3();
+                       });
 
                //Title left button
                Elm_Button *left_title_btn = elm_button_add(this->get_base());
@@ -55,18 +49,12 @@ protected:
        }
 
 public:
-       page2(appdata_s *ad) : ui_view("page2"), ad(ad)
-       {
-               //Push this view in viewmgr.
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page2()
-       {
-       }
+       page2() : ui_view("page2") {}
+       ~page2() {}
 };
 
-void create_page2(appdata_s *ad)
+void create_page2()
 {
-       new page2(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page2());
 }
index 87401d0..3c6dbba 100644 (file)
@@ -20,9 +20,6 @@
  */
 class page3: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -31,33 +28,25 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page4(ad);
-                               },
-                               this->ad);
+                                       create_page4();
+                               });
 
                //Arguments: content, title, subtitle, title left button, title right button
                this->set_content(content, "Title", "Subtitle", NULL, NULL);
        }
 
 public:
-       page3(appdata_s *ad) : ui_view("page3"), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page3()
-       {
-       }
+       page3() : ui_view("page3") {}
+       ~page3() {}
 };
 
-void create_page3(appdata_s *ad)
+void create_page3()
 {
-       new page3(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page3());
 }
index 21ad5ff..3c9ac18 100644 (file)
@@ -21,9 +21,6 @@
  */
 class page4: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -32,16 +29,13 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page5(ad);
-                               },
-                               this->ad);
+                                       create_page5();
+                               });
 
                //Arguments: content, title
                this->set_content(content, "TitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitleTitle");
@@ -49,17 +43,12 @@ protected:
        }
 
 public:
-       page4(appdata_s *ad) : ui_view("page4"), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page4()
-       {
-       }
+       page4() : ui_view("page4") {}
+       ~page4() {}
 };
 
-void create_page4(appdata_s *ad)
+void create_page4()
 {
-       new page4(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page4());
 }
index c30a8e5..420993e 100644 (file)
@@ -20,9 +20,6 @@
  */
 class page5: public ui_base_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -31,33 +28,25 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page6(ad);
-                               },
-                               this->ad);
+                                       create_page6();
+                               });
 
                this->set_content(content);
                this->set_indicator(UI_VIEW_INDICATOR_HIDE);
        }
 
 public:
-       page5(appdata_s *ad) : ui_base_view("page5"), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page5()
-       {
-       }
+       page5() : ui_base_view("page5") {}
+       ~page5() {}
 };
 
-void create_page5(appdata_s *ad)
+void create_page5()
 {
-       new page5(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page5());
 }
index a7faccd..b8fb69c 100644 (file)
@@ -19,9 +19,6 @@
  */
 class page6: public ui_view
 {
-private:
-       appdata_s *ad;
-
 protected:
        void on_load()
        {
@@ -30,16 +27,13 @@ protected:
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page7(ad);
-                               },
-                               this->ad);
+                                       create_page7();
+                               });
 
                //Arguments: content, title
                this->set_content(content, "Title with toolbar");
@@ -48,18 +42,12 @@ protected:
        }
 
 public:
-       page6(appdata_s *ad) : ui_view("page6"), ad(ad)
-       {
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page6()
-       {
-       }
+       page6() : ui_view("page6") {}
+       ~page6() {}
 };
 
-void create_page6(appdata_s *ad)
+void create_page6()
 {
-       /* A example for view class extension instead of using controller class. */
-       new page6(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page6());
 }
index bdf013e..089a483 100644 (file)
  */
 class page7: public ui_view
 {
-private:
-       appdata_s *ad;
-
 public:
-       page7(appdata_s *ad) : ui_view("page7"), ad(ad)
+       page7() : ui_view("page7")
        {
-               //FIXME: It will be deleted or change to other way :(
-               //       We don't have any way to support it now.
-               this->set_viewmgr(ad->viewmgr);
-
                //Create a main content.
                Evas_Object *content = create_content(this->get_base(), "ViewMgr Demo<br>Page 7<br>(Navigationbar style)",
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page8(ad);
-                               },
-                               this->ad);
+                                       create_page8();
+                               });
 
-               //Don't delete view's content when this view poped.
+               //FIXME: Don't delete view's content when this view poped.
                this->set_removable_content(false);
                this->set_content(content, "Title with toolbar");
                Elm_Toolbar *toolbar = create_toolbar(this->get_base(), "navigationbar");
                this->set_toolbar(toolbar);
-               ad->viewmgr->push_view(this);
-       }
-
-       ~page7()
-       {
        }
+       ~page7() {}
 };
 
-void create_page7(appdata_s *ad)
+void create_page7()
 {
-       new page7(ad);
+       //Push this view in viewmgr.
+       UI_VIEWMGR->push_view(new page7());
 }
index 37e1d77..53bff35 100644 (file)
  */
 class page8: public ui_controller
 {
-private:
-       appdata_s *ad;
-
-public:
-       page8(appdata_s *ad)
-                       : ad(ad)
-       {
-               /* ui_view(controller, identity name).
-                  Later, you could get the identity name using view->get_name(); */
-               ad->viewmgr->push_view(new ui_view(this, "page8"));
-       }
-       ~page8()
-       {
-       }
-
+protected:
        void on_load()
        {
                //Initialize contents.
                ui_view *view = dynamic_cast<ui_view *>(this->get_view());
 
                //Create a main content.
-               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 8",
+               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 8<br>(Controller Inheritance)",
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->pop_view();
+                                       UI_VIEWMGR->pop_view();
                                },
                                //Next Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
-                                       appdata_s *ad = static_cast<appdata_s *>(data);
-                                       create_page9(ad);
-                               },
-                               this->ad);
+                                       create_page9();
+                               });
 
                view->set_content(content, "Title");
        }
+public:
+       page8()
+       {
+               UI_VIEWMGR->push_view(new ui_view(this, "page8"));
+       }
+       ~page8() {}
 };
 
-void create_page8(appdata_s *ad)
+void create_page8()
 {
-       new page8(ad);
+       page8 *controller = new page8();
 }
index ae9e4c3..f70c232 100644 (file)
  */
 class page9: public ui_controller
 {
-private:
-       appdata_s *ad;
-
 public:
-       page9(appdata_s *ad)
-                       : ad(ad)
+       page9()
        {
                ui_view *view = new ui_view(this, "page9");
 
-               //FIXME: It will be deleted or change to other way :(
-               //       We don't have any way to support it now.
-               view->set_viewmgr(ad->viewmgr);
-
                //Create a main content.
-               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 9<br>(Content Preloading)",
+               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 9<br>(Controller Inheritance + Content Preloading)",
                        //Prev Button Callback
                        [](void *data, Evas_Object *obj, void *event_info) -> void
                        {
-                               appdata_s *ad = static_cast<appdata_s *>(data);
-                               ad->viewmgr->pop_view();
+                               UI_VIEWMGR->pop_view();
                        },
                        //Next Button Callback
                        [](void *data, Evas_Object *obj, void *event_info) -> void
                        {
-                               appdata_s *ad = static_cast<appdata_s *>(data);
-                               create_page10(ad);
-                       },
-                       this->ad);
+                               create_page10();
+                       });
 
                //Don't delete view's content when this view poped.
                view->set_removable_content(false);
                view->set_content(content, "Title");
-               ad->viewmgr->push_view(view);
-       }
-       ~page9()
-       {
+
+               UI_VIEWMGR->push_view(view);
        }
+       ~page9() {}
 };
 
-void create_page9(appdata_s *ad)
+void create_page9()
 {
-       new page9(ad);
+       page9 *controller = new page9();
 }
index 6260473..58e0017 100644 (file)
 namespace efl_viewmgr
 {
 class ui_menu;
+class ui_viewmgr;
 
 class ui_controller: public ui_base_controller
 {
+       friend class ui_viewmgr;
+       friend class ui_view;
+
+protected:
+       virtual void on_menu(ui_menu *menu);
+
 public:
        virtual ~ui_controller();
-       virtual void on_menu(ui_menu *menu);
 };
 }
 
index 1dacd1f..5dc1227 100644 (file)
@@ -26,6 +26,7 @@ class ui_view: public ui_base_view
 {
        friend class ui_menu;
        friend class ui_key_listener;
+       friend class ui_controller;
 
 private:
        Elm_Layout *layout;                //Base layout for view
@@ -40,7 +41,9 @@ private:
 protected:
        virtual void on_load();
        virtual void on_unload();
-       virtual void on_menu();
+       bool on_menu_pre();
+       void on_menu_post();
+       virtual void on_menu(ui_menu *menu);
        virtual void unload_content();
        virtual void set_event_block(bool block);
        virtual void on_back();
@@ -75,11 +78,7 @@ public:
        Elm_Button *unset_title_right_btn();
        Elm_Toolbar *unset_toolbar();
 
-       virtual Evas_Object *get_base()
-       {
-               if (!this->layout)this->create_layout();
-               return this->layout;
-       }
+       virtual Evas_Object *get_base();
 
        Elm_Button *get_title_left_btn()
        {
index dc2f7d1..a0bb471 100644 (file)
@@ -26,3 +26,5 @@
 #include "ui_key_listener.h"
 #include "ui_viewmgr.h"
 #include "ui_menu.h"
+
+#define UI_VIEWMGR dynamic_cast<ui_viewmgr *>(efl_viewmgr::ui_base_viewmgr::get_instance())
index e5a97b5..314f3f2 100644 (file)
@@ -14,8 +14,8 @@
  *  limitations under the License.
  *
  */
-#ifndef UI_BASIC_VIEWMGR_H
-#define UI_BASIC_VIEWMGR_H
+#ifndef UI_VIEWMGR_H
+#define UI_VIEWMGR_H
 
 #include <Elementary.h>
 #include "../ui_viewmanager_base.h"
@@ -24,14 +24,15 @@ namespace efl_viewmgr
 {
 
 class ui_view;
+class ui_viewmgr;
 
 class ui_viewmgr: public ui_base_viewmgr
 {
        friend class ui_view;
+       friend class ui_controller;
 
 public:
        ui_viewmgr(const char *pkg);
-
        virtual ~ui_viewmgr();
 
 };
index b732278..d93f4eb 100644 (file)
@@ -31,23 +31,9 @@ namespace efl_viewmgr
  */
 class ui_base_controller: public viewmgr::ui_iface_controller
 {
-public:
-       ///Destructor.
-       virtual ~ui_base_controller();
-
-       /**
-        *  @brief Return a view which is matched with controller
-        *
-        *  @return The view which is matched with controller
-        *
-        *  @note User can set a controller 2 ways, 1. send a controller instance when view created,
-        *        2. call set_view() method with controller instance.
-        *
-        *  @see set_view()
-        */
-
-       ui_base_view *get_view();
+       friend class ui_base_view;
 
+protected:
        /** @brief load callback.
         *
         *  @note Now, this view is moving onto the screen. Get ready for this view. If this view content is alive, load callback won't be called.
@@ -131,6 +117,22 @@ public:
         */
        virtual bool on_back() { return true; }
 
+public:
+       ///Destructor.
+       virtual ~ui_base_controller();
+
+       /**
+        *  @brief Return a view which is matched with controller
+        *
+        *  @return The view which is matched with controller
+        *
+        *  @note User can set a controller 2 ways, 1. send a controller instance when view created,
+        *        2. call set_view() method with controller instance.
+        *
+        *  @see set_view()
+        */
+
+       ui_base_view *get_view();
 };
 }
 
diff --git a/src/include/efl/ui_base_singleton.h b/src/include/efl/ui_base_singleton.h
new file mode 100644 (file)
index 0000000..7b1473c
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef UI_SINGLETON_UTIL_H
+#define UI_SINGLETON_UTIL_H
+
+#include <cassert>
+
+using namespace std;
+
+namespace efl_viewmgr
+{
+
+template<typename T>
+class singleton
+{
+private:
+       static T* inst;
+
+public:
+       singleton();
+       virtual ~singleton();
+       inline static T* get_instance();
+};
+
+template<typename T> T* singleton<T>::inst = NULL;
+
+template<typename T>
+singleton<T>::singleton()
+{
+       assert(!singleton::inst);
+
+       T* pT = reinterpret_cast<T*>(1);
+
+       //Derived Class - Singleton class
+       int offset = reinterpret_cast<int>(pT) - reinterpret_cast<int>(reinterpret_cast<singleton<T>*>(pT));
+    singleton::inst = reinterpret_cast<T*>((reinterpret_cast<int>(this) + offset));
+}
+
+template<typename T>
+singleton<T>::~singleton()
+{
+       assert(singleton::inst);
+       singleton::inst = NULL;
+}
+
+template<typename T>
+T* singleton<T>::get_instance()
+{
+       assert(singleton::inst);
+    return singleton::inst;
+}
+
+}
+
+#endif /* UI_SINGLETON_UTIL_H_ */
index 89b3b35..2c8b960 100644 (file)
@@ -44,7 +44,7 @@ class ui_base_view;
  *
  *  @warning viewmgr will remove all containing views when it's destroyed.
  */
-class ui_base_viewmgr: public viewmgr::ui_iface_viewmgr
+class ui_base_viewmgr: public singleton<ui_base_viewmgr>, public viewmgr::ui_iface_viewmgr
 {
        friend class ui_base_view;
 
index c2659ec..33f383f 100644 (file)
 #endif
 #define LOG_TAG "UI_VIEWMGR"
 
+#include "ui_base_singleton.h"
 #include "ui_base_viewmgr.h"
 #include "ui_base_controller.h"
 #include "ui_base_view.h"
 #include "ui_base_key_listener.h"
 #include "ui_base_popup.h"
+
+
+#define UI_BASE_VIEWMGR efl_viewmgr::ui_base_viewmgr::get_instance()
index ebef728..769965b 100644 (file)
@@ -54,18 +54,6 @@ protected:
                return this->view;
        }
 
-public:
-       ///Constructor.
-       ui_iface_controller() :
-                       view(NULL)
-       {
-       }
-
-       ///Destructor.
-       virtual ~ui_iface_controller()
-       {
-       }
-
        /** @brief load callback.
         *
         *  @note Now, this view is moving onto the screen. Get ready for this view. If this view content is alive, load callback won't be called.
@@ -140,6 +128,19 @@ public:
         *  @note When current view is on landscape mode.
         */
        virtual void on_landscape() = 0;
+
+
+public:
+       ///Constructor.
+       ui_iface_controller() :
+                       view(NULL)
+       {
+       }
+
+       ///Destructor.
+       virtual ~ui_iface_controller()
+       {
+       }
 };
 
 }
index f258dbc..577ff07 100644 (file)
@@ -172,12 +172,6 @@ protected:
        ui_iface_controller* set_controller(ui_iface_controller *controller);
 
 public:
-       //FIXME: This method for support a use case that user make content, view same time.
-       void set_viewmgr(ui_iface_viewmgr *viewmgr)
-       {
-               this->viewmgr = viewmgr;
-       }
-
        /** @brief This is a constructor for initializing this view resources.
         *
         *  @param controller view life-cycle controller interface.
index 61acc66..dcad91d 100644 (file)
@@ -30,13 +30,15 @@ ui_key_listener::ui_key_listener(ui_viewmgr *viewmgr)
 void ui_key_listener::extend_event_proc(ui_base_view *view, Evas_Event_Key_Down *ev)
 {
        if (strcmp(ev->keyname, KEY_MENU) && strcmp(ev->keyname, KEY_MENU2)) return;
-       dynamic_cast<ui_view *>(view)->on_menu();
+       ui_view *v = dynamic_cast<ui_view *>(view);
+       if (!v->on_menu_pre()) return;
+       v->on_menu((ui_menu*)(v->get_menu()));
+       v->on_menu_post();
 }
 
 bool ui_key_listener::init()
 {
        if (!ui_base_key_listener::init()) return false;
-
        if (!evas_object_key_grab(this->key_grabber, KEY_MENU, 0, 0, EINA_FALSE))
        {
                LOGE("Failed to grab MENU KEY(%s)\n", KEY_MENU);
index 2c01297..27853bf 100644 (file)
@@ -84,7 +84,7 @@ ui_menu::~ui_menu()
 
 Elm_Win *ui_menu::get_window()
 {
-       ui_viewmgr *viewmgr = dynamic_cast<ui_viewmgr *>(this->view->get_viewmgr());
+       ui_viewmgr *viewmgr = UI_VIEWMGR;
        if (!viewmgr)
        {
                LOGE("Viewmgr is null?? menu(%p)", this);
index 42ed2d6..c5bf06b 100644 (file)
@@ -23,7 +23,6 @@
 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 content_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
@@ -86,8 +85,8 @@ bool ui_view::create_layout()
        }
 
        //Set software back key, if it's needed
-       ui_viewmgr *viewmgr = MY_VIEWMGR;
-       if (viewmgr->need_soft_key())
+       ui_viewmgr *viewmgr = UI_VIEWMGR;
+       if (viewmgr && viewmgr->need_soft_key())
        {
                Elm_Button *prev_btn = elm_button_add(layout);
 
@@ -323,23 +322,32 @@ void ui_view::unload_content()
        this->destroy_layout();
 }
 
-void ui_view::on_menu()
+bool ui_view::on_menu_pre()
 {
        if (this->menu && this->menu->is_activated())
        {
                this->menu->deactivate();
-               return;
+               return false;
+       }
+       if (!this->menu)
+       {
+               this->menu = new ui_menu(this);
        }
 
        if (this->get_controller())
        {
-               if (!this->menu)
-               {
-                       this->menu = new ui_menu(this);
-               }
                MY_CONTROLLER->on_menu(this->menu);
+               return false;
        }
+       return true;
+}
 
+void ui_view::on_menu(ui_menu *menu)
+{
+}
+
+void ui_view::on_menu_post()
+{
        if (this->menu && this->menu->get_content())
        {
                this->menu->activate();
@@ -436,3 +444,9 @@ void ui_view::on_landscape()
                this->menu->on_landscape();
        }
 }
+
+Evas_Object *ui_view::get_base()
+{
+       if (!this->layout) this->create_layout();
+       return this->layout;
+}
index 588f4a9..0a56bb8 100644 (file)
@@ -57,7 +57,7 @@ ui_base_popup::~ui_base_popup()
 
 Elm_Win *ui_base_popup::get_window()
 {
-       ui_base_viewmgr *viewmgr = dynamic_cast<ui_base_viewmgr *>(this->view->get_viewmgr());
+       ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR;
        if (!viewmgr)
        {
                LOGE("Viewmgr is null?? menu(%p)", this);
index a01da67..4a4d896 100644 (file)
@@ -20,7 +20,6 @@ using namespace efl_viewmgr;
 using namespace viewmgr;
 
 #define MY_CONTROLLER dynamic_cast<ui_base_controller *>(this->get_controller())
-#define MY_VIEWMGR dynamic_cast<ui_base_viewmgr *>(this->get_viewmgr())
 typedef list<ui_base_popup*>::reverse_iterator popup_ritr;
 
 void ui_base_view::connect_popup(ui_base_popup *popup)
@@ -64,7 +63,7 @@ Evas_Object *ui_base_view::unset_content()
 
 Evas_Object *ui_base_view::get_base()
 {
-       ui_base_viewmgr *viewmgr = MY_VIEWMGR;
+       ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR;
        if (!viewmgr)
        {
                return NULL;
@@ -82,7 +81,7 @@ void ui_base_view::unload_content()
 
 Evas_Object *ui_base_view ::get_parent()
 {
-       ui_base_viewmgr *viewmgr = MY_VIEWMGR;
+       ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR;
        if (!viewmgr)
        {
                LOGE("Failed to get a viewmgr");
@@ -97,7 +96,12 @@ void ui_base_view::set_indicator(ui_view_indicator indicator)
 
        ui_iface_view::set_indicator(indicator);
 
-       ui_base_viewmgr *viewmgr = MY_VIEWMGR;
+       ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR;
+       if (!viewmgr)
+       {
+               LOGE("Failed to get a viewmgr");
+               return;
+       }
 
        if (!viewmgr->is_activated()) return;
 
@@ -137,7 +141,13 @@ void ui_base_view::on_back()
                        return;
                }
        }
-       MY_VIEWMGR->pop_view();
+       ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR;
+       if (!viewmgr)
+       {
+               LOGE("Failed to get a viewmgr");
+               return;
+       }
+       viewmgr->pop_view();
 }
 
 void ui_base_view::on_rotate(int degree)
@@ -165,7 +175,7 @@ void ui_base_view::set_event_block(bool block)
 
 int ui_base_view::get_degree()
 {
-       ui_base_viewmgr *viewmgr = MY_VIEWMGR;
+       ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR;
        if (!viewmgr)
        {
                LOGE("Failed to get a viewmgr");
index 7c20cad..970b802 100644 (file)
@@ -170,7 +170,7 @@ bool ui_base_viewmgr::create_conformant(Elm_Win *win)
 }
 
 ui_base_viewmgr::ui_base_viewmgr(const char *pkg, ui_base_key_listener *key_listener)
-               : ui_iface_viewmgr(), key_listener(key_listener), transition_style("default")
+               : singleton(), ui_iface_viewmgr(), key_listener(key_listener), transition_style("default")
 {
        if (!pkg)
        {