From: Hermet Park Date: Tue, 29 Mar 2016 14:20:53 +0000 (+0900) Subject: ui_viewmgr: change to singleton instance and update examples. X-Git-Tag: submit/tizen/20160617.075742~76 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F50%2F64050%2F2;p=platform%2Fcore%2Fuifw%2Fui-viewmgr.git ui_viewmgr: change to singleton instance and update examples. Conflicts: src/examples/efl/page14.h src/examples/efl/page15.h Change-Id: I6fdc86f7ffa0708d6b6b526a27ad047a3e15b8d8 --- diff --git a/src/examples/efl/main.cpp b/src/examples/efl/main.cpp index f97ac27..143497a 100644 --- a/src/examples/efl/main.cpp +++ b/src/examples/efl/main.cpp @@ -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(calloc(1, sizeof(appdata_s))); + + //FIXME: Hide this creation. + ui_viewmgr *viewmgr = new ui_viewmgr(PACKAGE); + create_base_gui(ad); elm_run(); diff --git a/src/examples/efl/main.h b/src/examples/efl/main.h index abc7ac7..321bc69 100644 --- a/src/examples/efl/main.h +++ b/src/examples/efl/main.h @@ -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); diff --git a/src/examples/efl/page1.h b/src/examples/efl/page1.h index 5ce77b3..5a0e4e3 100644 --- a/src/examples/efl/page1.h +++ b/src/examples/efl/page1.h @@ -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(data); - ad->viewmgr->deactivate(); + UI_VIEWMGR->deactivate(); }, //Next Button Callback [](void *data, Evas_Object *obj, void *event_info) -> void { - appdata_s *ad = static_cast(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()); } diff --git a/src/examples/efl/page10.h b/src/examples/efl/page10.h index e3be5ed..9dadddd 100644 --- a/src/examples/efl/page10.h +++ b/src/examples/efl/page10.h @@ -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
Page 10
(Portrait + Landscape)", //Prev Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(data); - ad->viewmgr->pop_view(); - }, - //Next Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(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
Page 10
(Portrait + Landscape)", //Prev Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(data); - ad->viewmgr->pop_view(); - }, - //Next Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(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()); } diff --git a/src/examples/efl/page11.h b/src/examples/efl/page11.h index 9a5ed79..9312359 100644 --- a/src/examples/efl/page11.h +++ b/src/examples/efl/page11.h @@ -21,24 +21,10 @@ */ 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(this->get_view()); - this->on_rotate(view->get_degree()); } @@ -51,18 +37,15 @@ public: { Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 11
(Rotate)", //Prev Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(data); - ad->viewmgr->pop_view(); - }, - //Next Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(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
Page 11
(Rotate)", //Prev Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(data); - ad->viewmgr->pop_view(); - }, - //Next Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(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(); } diff --git a/src/examples/efl/page12.h b/src/examples/efl/page12.h index 2f8fff3..c65c976 100644 --- a/src/examples/efl/page12.h +++ b/src/examples/efl/page12.h @@ -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(this->get_view()); - //Create a main content. - Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 12
(Menu Popup)", + Evas_Object *content = create_content(this->get_base(), "ViewMgr Demo
Page 12
(Menu Popup)", //Prev Button Callback [](void *data, Evas_Object *obj, void *event_info) -> void { - appdata_s *ad = static_cast(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(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()); } diff --git a/src/examples/efl/page13.h b/src/examples/efl/page13.h index c9e0db1..27e940b 100644 --- a/src/examples/efl/page13.h +++ b/src/examples/efl/page13.h @@ -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(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(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()); } diff --git a/src/examples/efl/page14.h b/src/examples/efl/page14.h index 6a15217..3003dc8 100644 --- a/src/examples/efl/page14.h +++ b/src/examples/efl/page14.h @@ -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(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(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()); } diff --git a/src/examples/efl/page15.h b/src/examples/efl/page15.h index b4e32a5..2cbf09a 100644 --- a/src/examples/efl/page15.h +++ b/src/examples/efl/page15.h @@ -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(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(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()); } diff --git a/src/examples/efl/page2.h b/src/examples/efl/page2.h index d5def0d..dd3986c 100644 --- a/src/examples/efl/page2.h +++ b/src/examples/efl/page2.h @@ -20,27 +20,21 @@ */ 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
Page 2", - //Prev Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(data); - ad->viewmgr->pop_view(); - }, - //Next Button Callback - [](void *data, Evas_Object *obj, void *event_info) -> void - { - appdata_s *ad = static_cast(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()); } diff --git a/src/examples/efl/page3.h b/src/examples/efl/page3.h index 87401d0..3c6dbba 100644 --- a/src/examples/efl/page3.h +++ b/src/examples/efl/page3.h @@ -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(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(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()); } diff --git a/src/examples/efl/page4.h b/src/examples/efl/page4.h index 21ad5ff..3c9ac18 100644 --- a/src/examples/efl/page4.h +++ b/src/examples/efl/page4.h @@ -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(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(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()); } diff --git a/src/examples/efl/page5.h b/src/examples/efl/page5.h index c30a8e5..420993e 100644 --- a/src/examples/efl/page5.h +++ b/src/examples/efl/page5.h @@ -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(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(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()); } diff --git a/src/examples/efl/page6.h b/src/examples/efl/page6.h index a7faccd..b8fb69c 100644 --- a/src/examples/efl/page6.h +++ b/src/examples/efl/page6.h @@ -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(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(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()); } diff --git a/src/examples/efl/page7.h b/src/examples/efl/page7.h index bdf013e..089a483 100644 --- a/src/examples/efl/page7.h +++ b/src/examples/efl/page7.h @@ -20,46 +20,33 @@ */ 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
Page 7
(Navigationbar style)", //Prev Button Callback [](void *data, Evas_Object *obj, void *event_info) -> void { - appdata_s *ad = static_cast(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(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()); } diff --git a/src/examples/efl/page8.h b/src/examples/efl/page8.h index 37e1d77..53bff35 100644 --- a/src/examples/efl/page8.h +++ b/src/examples/efl/page8.h @@ -19,47 +19,36 @@ */ 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(this->get_view()); //Create a main content. - Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 8", + Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 8
(Controller Inheritance)", //Prev Button Callback [](void *data, Evas_Object *obj, void *event_info) -> void { - appdata_s *ad = static_cast(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(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(); } diff --git a/src/examples/efl/page9.h b/src/examples/efl/page9.h index ae9e4c3..f70c232 100644 --- a/src/examples/efl/page9.h +++ b/src/examples/efl/page9.h @@ -20,46 +20,34 @@ */ 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
Page 9
(Content Preloading)", + Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo
Page 9
(Controller Inheritance + Content Preloading)", //Prev Button Callback [](void *data, Evas_Object *obj, void *event_info) -> void { - appdata_s *ad = static_cast(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(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(); } diff --git a/src/include/efl/mobile/ui_controller.h b/src/include/efl/mobile/ui_controller.h index 6260473..58e0017 100644 --- a/src/include/efl/mobile/ui_controller.h +++ b/src/include/efl/mobile/ui_controller.h @@ -22,12 +22,18 @@ 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); }; } diff --git a/src/include/efl/mobile/ui_view.h b/src/include/efl/mobile/ui_view.h index 1dacd1f..5dc1227 100644 --- a/src/include/efl/mobile/ui_view.h +++ b/src/include/efl/mobile/ui_view.h @@ -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() { diff --git a/src/include/efl/mobile/ui_viewmanager.h b/src/include/efl/mobile/ui_viewmanager.h index dc2f7d1..a0bb471 100644 --- a/src/include/efl/mobile/ui_viewmanager.h +++ b/src/include/efl/mobile/ui_viewmanager.h @@ -26,3 +26,5 @@ #include "ui_key_listener.h" #include "ui_viewmgr.h" #include "ui_menu.h" + +#define UI_VIEWMGR dynamic_cast(efl_viewmgr::ui_base_viewmgr::get_instance()) diff --git a/src/include/efl/mobile/ui_viewmgr.h b/src/include/efl/mobile/ui_viewmgr.h index e5a97b5..314f3f2 100644 --- a/src/include/efl/mobile/ui_viewmgr.h +++ b/src/include/efl/mobile/ui_viewmgr.h @@ -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 #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(); }; diff --git a/src/include/efl/ui_base_controller.h b/src/include/efl/ui_base_controller.h index b732278..d93f4eb 100644 --- a/src/include/efl/ui_base_controller.h +++ b/src/include/efl/ui_base_controller.h @@ -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 index 0000000..7b1473c --- /dev/null +++ b/src/include/efl/ui_base_singleton.h @@ -0,0 +1,53 @@ +#ifndef UI_SINGLETON_UTIL_H +#define UI_SINGLETON_UTIL_H + +#include + +using namespace std; + +namespace efl_viewmgr +{ + +template +class singleton +{ +private: + static T* inst; + +public: + singleton(); + virtual ~singleton(); + inline static T* get_instance(); +}; + +template T* singleton::inst = NULL; + +template +singleton::singleton() +{ + assert(!singleton::inst); + + T* pT = reinterpret_cast(1); + + //Derived Class - Singleton class + int offset = reinterpret_cast(pT) - reinterpret_cast(reinterpret_cast*>(pT)); + singleton::inst = reinterpret_cast((reinterpret_cast(this) + offset)); +} + +template +singleton::~singleton() +{ + assert(singleton::inst); + singleton::inst = NULL; +} + +template +T* singleton::get_instance() +{ + assert(singleton::inst); + return singleton::inst; +} + +} + +#endif /* UI_SINGLETON_UTIL_H_ */ diff --git a/src/include/efl/ui_base_viewmgr.h b/src/include/efl/ui_base_viewmgr.h index 89b3b35..2c8b960 100644 --- a/src/include/efl/ui_base_viewmgr.h +++ b/src/include/efl/ui_base_viewmgr.h @@ -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, public viewmgr::ui_iface_viewmgr { friend class ui_base_view; diff --git a/src/include/efl/ui_viewmanager_base.h b/src/include/efl/ui_viewmanager_base.h index c2659ec..33f383f 100644 --- a/src/include/efl/ui_viewmanager_base.h +++ b/src/include/efl/ui_viewmanager_base.h @@ -21,8 +21,12 @@ #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() diff --git a/src/include/interface/ui_iface_controller.h b/src/include/interface/ui_iface_controller.h index ebef728..769965b 100644 --- a/src/include/interface/ui_iface_controller.h +++ b/src/include/interface/ui_iface_controller.h @@ -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() + { + } }; } diff --git a/src/include/interface/ui_iface_view.h b/src/include/interface/ui_iface_view.h index f258dbc..577ff07 100644 --- a/src/include/interface/ui_iface_view.h +++ b/src/include/interface/ui_iface_view.h @@ -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. diff --git a/src/lib/efl/mobile/ui_key_listener.cpp b/src/lib/efl/mobile/ui_key_listener.cpp index 61acc66..dcad91d 100644 --- a/src/lib/efl/mobile/ui_key_listener.cpp +++ b/src/lib/efl/mobile/ui_key_listener.cpp @@ -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(view)->on_menu(); + ui_view *v = dynamic_cast(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); diff --git a/src/lib/efl/mobile/ui_menu.cpp b/src/lib/efl/mobile/ui_menu.cpp index 2c01297..27853bf 100644 --- a/src/lib/efl/mobile/ui_menu.cpp +++ b/src/lib/efl/mobile/ui_menu.cpp @@ -84,7 +84,7 @@ ui_menu::~ui_menu() Elm_Win *ui_menu::get_window() { - ui_viewmgr *viewmgr = dynamic_cast(this->view->get_viewmgr()); + ui_viewmgr *viewmgr = UI_VIEWMGR; if (!viewmgr) { LOGE("Viewmgr is null?? menu(%p)", this); diff --git a/src/lib/efl/mobile/ui_view.cpp b/src/lib/efl/mobile/ui_view.cpp index 42ed2d6..c5bf06b 100644 --- a/src/lib/efl/mobile/ui_view.cpp +++ b/src/lib/efl/mobile/ui_view.cpp @@ -23,7 +23,6 @@ using namespace efl_viewmgr; using namespace viewmgr; -#define MY_VIEWMGR dynamic_cast(this->get_viewmgr()) #define MY_CONTROLLER dynamic_cast(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; +} diff --git a/src/lib/efl/ui_base_popup.cpp b/src/lib/efl/ui_base_popup.cpp index 588f4a9..0a56bb8 100644 --- a/src/lib/efl/ui_base_popup.cpp +++ b/src/lib/efl/ui_base_popup.cpp @@ -57,7 +57,7 @@ ui_base_popup::~ui_base_popup() Elm_Win *ui_base_popup::get_window() { - ui_base_viewmgr *viewmgr = dynamic_cast(this->view->get_viewmgr()); + ui_base_viewmgr *viewmgr = UI_BASE_VIEWMGR; if (!viewmgr) { LOGE("Viewmgr is null?? menu(%p)", this); diff --git a/src/lib/efl/ui_base_view.cpp b/src/lib/efl/ui_base_view.cpp index a01da67..4a4d896 100644 --- a/src/lib/efl/ui_base_view.cpp +++ b/src/lib/efl/ui_base_view.cpp @@ -20,7 +20,6 @@ using namespace efl_viewmgr; using namespace viewmgr; #define MY_CONTROLLER dynamic_cast(this->get_controller()) -#define MY_VIEWMGR dynamic_cast(this->get_viewmgr()) typedef list::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"); diff --git a/src/lib/efl/ui_base_viewmgr.cpp b/src/lib/efl/ui_base_viewmgr.cpp index 7c20cad..970b802 100644 --- a/src/lib/efl/ui_base_viewmgr.cpp +++ b/src/lib/efl/ui_base_viewmgr.cpp @@ -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) {