viewmgr: Add page7 example. 78/61778/5
authorWoochan Lee <wc0917.lee@samsung.com>
Thu, 10 Mar 2016 11:41:50 +0000 (20:41 +0900)
committerWoochan Lee <wc0917.lee@samsung.com>
Fri, 11 Mar 2016 08:05:07 +0000 (17:05 +0900)
Directly make a view and content in the same function.

Change-Id: Id470c7af4cbcc116b0ad304424c0119de85518ae

src/examples/efl/main.cpp
src/examples/efl/main.h
src/examples/efl/page6.h
src/examples/efl/page7.h [new file with mode: 0644]
src/include/efl/mobile/ui_basic_view.h
src/include/interface/ui_iface_view.h
src/lib/efl/mobile/ui_basic_view.cpp
src/lib/efl/ui_view.cpp
src/lib/interface/ui_iface_view.cpp
src/lib/interface/ui_iface_viewmgr.cpp

index e10e8c0..459d25d 100644 (file)
@@ -15,6 +15,7 @@
  *
  */
 #include "main.h"
+#include "page7.h"
 #include "page6.h"
 #include "page5.h"
 #include "page4.h"
 #include "page1.h"
 
 Evas_Object*
-create_toolbar(Evas_Object *parent)
+create_toolbar(Evas_Object *parent, const char *style)
 {
        Evas_Object *toolbar;
 
        toolbar = elm_toolbar_add(parent);
 
        //FIXME: :( UI_View can set this style instead.
-       elm_object_style_set(toolbar, "toolbar_with_title");
+       elm_object_style_set(toolbar, style);
+
+       //FIXME: If not call below API, toolbar items create with min size.
+       //       It looks toolbar bug.
        elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
-       elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
 
        elm_toolbar_item_append(toolbar, NULL, "Tab1", NULL, NULL);
        elm_toolbar_item_append(toolbar, NULL, "Tab2", NULL, NULL);
-
-       elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
+       elm_toolbar_item_append(toolbar, NULL, "Tab3", NULL, NULL);
+       elm_toolbar_item_append(toolbar, NULL, "Tab4", NULL, NULL);
 
        return toolbar;
 }
index f508a1a..0535e7e 100644 (file)
@@ -40,4 +40,4 @@ typedef struct appdata {
 } appdata_s;
 
 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_toolbar(Evas_Object *parent);
+Evas_Object *create_toolbar(Evas_Object *parent, const char *style);
index 9fad923..a7ad601 100644 (file)
@@ -23,9 +23,8 @@ public:
        page6(appdata_s *ad)
                : ad(ad)
        {
-               /* ui_basic_view(controller, identity name, style name of view).
-                  Later, you could get the identity name using view->get_name();
-                  you could get the style name of view as well */
+               /* ui_basic_view(controller, identity name).
+                  Later, you could get the identity name using view->get_name(); */
                ad->viewmgr->push_view(new ui_basic_view(this, "page6"));
        }
 
@@ -41,7 +40,7 @@ public:
                ui_basic_view *view = dynamic_cast<ui_basic_view *>(this->get_view());
 
                //Create a main content.
-               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 6<br>With Tabar",
+               Evas_Object *content = create_content(view->get_base(), "ViewMgr Demo<br>Page 6<br>With Toolbar<br>(tabbar style)",
                                //Prev Button Callback
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
@@ -52,13 +51,13 @@ public:
                                [](void *data, Evas_Object *obj, void *event_info) -> void
                                {
                                        appdata_s *ad = static_cast<appdata_s *>(data);
-                                       ad->viewmgr->deactivate();
+                                       create_page7(ad);
                                },
                                this->ad);
 
                //Arguments: content, title
                view->set_content(content, "Title with toolbar");
-               Evas_Object *toolbar = create_toolbar(view->get_base());
+               Evas_Object *toolbar = create_toolbar(view->get_base(), "toolbar_with_title");
                view->set_toolbar(toolbar);
        }
 };
diff --git a/src/examples/efl/page7.h b/src/examples/efl/page7.h
new file mode 100644 (file)
index 0000000..a6bafb5
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ *
+ */
+class page7: public ui_basic_controller
+{
+private:
+       appdata_s *ad;
+
+public:
+       page7(appdata_s *ad)
+               : ad(ad)
+       {
+               /* ui_basic_view(controller, identity name, style name of view).
+                  Later, you could get the identity name using view->get_name();
+                  you could get the style name of view as well */
+               ui_basic_view *view = new ui_basic_view(this, "page7");
+
+               //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 7<br>With Toolbar<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();
+                               },
+                               //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);
+
+               view->set_content(content, "Title with toolbar");
+               Evas_Object *toolbar = create_toolbar(view->get_base(), "navigationbar");
+               view->set_toolbar(toolbar);
+               ad->viewmgr->push_view(view);
+       }
+
+       ~page7()
+       {
+       }
+};
+
+void create_page7(appdata_s *ad)
+{
+       new page7(ad);
+}
index e6bda73..297efb1 100644 (file)
@@ -52,6 +52,7 @@ public:
 
        virtual Evas_Object *get_base()
        {
+               if (!this->layout)this->create_layout();
                return this->layout;
        }
 };
index 5ceeb8a..597ce37 100644 (file)
@@ -172,16 +172,20 @@ 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 content A content instance for a screen as a view.
         *  @param controller view life-cycle controller interface.
         *  @param name view name.
         *
         *  @warning Be aware the deletion of controller passed here will be covered by ui_iface_view.
         *           If you want to keep it for any reasons, please unset it using set_controller() before ui_iface_view is deleted.
         */
-       ui_iface_view(T content, ui_iface_controller *controller, const char *name);
        ///Constructor for initializing with controller.
        ui_iface_view(ui_iface_controller *controller, const char *name = NULL);
        ///Constructor for initializing with name.
index ef15fee..f7f68d0 100644 (file)
@@ -101,7 +101,7 @@ ui_basic_view::~ui_basic_view()
 
 void ui_basic_view::load()
 {
-       this->create_layout();
+       if (!this->layout) this->create_layout();
        ui_view::load();
 }
 
@@ -228,6 +228,24 @@ bool ui_basic_view::set_toolbar(Evas_Object *toolbar)
 
        if (layout)
        {
+
+               if ((!strcmp(elm_object_style_get(toolbar), "toolbar_with_title")) &&
+                   ((elm_toolbar_shrink_mode_get(toolbar) != ELM_TOOLBAR_SHRINK_EXPAND)))
+               {
+                       elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
+               }
+               else if (!strcmp(elm_object_style_get(toolbar), "navigationbar"))
+               {
+                       if (elm_toolbar_shrink_mode_get(toolbar) != ELM_TOOLBAR_SHRINK_SCROLL)
+                               elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_SCROLL);
+                       elm_toolbar_align_set(toolbar, 0.0);
+               }
+               elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
+
+               //FIXME: It can be deleted when the application want to handle this property.
+               //       Some of application may want to select one of toolbar item when view activated.
+               elm_toolbar_select_mode_set(toolbar, ELM_OBJECT_SELECT_MODE_ALWAYS);
+
                elm_object_part_content_set(layout, "toolbar", toolbar);
                if (toolbar) elm_object_signal_emit(layout, "elm,state,toolbar,show", "elm");
                else elm_object_signal_emit(layout, "elm,state,toolbar,hide", "elm");
index dfa66f4..a50329b 100644 (file)
@@ -53,6 +53,11 @@ void ui_view::unload_content()
 Evas_Object *ui_view ::get_parent()
 {
        ui_viewmgr *viewmgr = dynamic_cast<ui_viewmgr *>(this->get_viewmgr());
+       if (!viewmgr)
+       {
+               LOGE("Failed to get a viewmgr");
+               return NULL;
+       }
        return viewmgr->get_base();
 }
 
index 8348563..ca9b444 100644 (file)
@@ -82,19 +82,12 @@ void ui_iface_view::destroy()
        this->controller->destroy();
 }
 
-ui_iface_view::ui_iface_view(T content, ui_iface_controller *controller, const char *name)
-               : content(content), controller(controller), name(string(name ? name : "")), style(string("")), viewmgr(NULL), state(UI_VIEW_STATE_LOAD),
-                 indicator(UI_VIEW_INDICATOR_DEFAULT), event_block(false), removable_content(true)
-{
-       if (!content) this->state = UI_VIEW_STATE_UNLOAD;
-       else this->state = UI_VIEW_STATE_LOAD;
-       controller->set_view(this);
-}
-
 ui_iface_view::ui_iface_view(ui_iface_controller *controller, const char *name)
-               : ui_iface_view(NULL, controller, name)
+               : content(NULL), controller(controller), name(string(name ? name : "")), style(string("")), viewmgr(NULL), state(UI_VIEW_STATE_LOAD),
+                 indicator(UI_VIEW_INDICATOR_DEFAULT), event_block(false), removable_content(true)
 {
        this->state = UI_VIEW_STATE_UNLOAD;
+       controller->set_view(this);
 }
 
 ui_iface_view::ui_iface_view(const char *name)
index 164f987..5f19c90 100644 (file)
@@ -30,11 +30,14 @@ bool ui_iface_viewmgr::need_soft_key()
 
 bool ui_iface_viewmgr::connect_view(ui_iface_view *view)
 {
+       //FIXME: If user call a set_viewmgr() before, It should not return false.
+       /*
        if (view->viewmgr)
        {
                LOGE("view(%p) has already connected to viewmgr(%p)", view, this);
                return false;
        }
+       */
 
        view->viewmgr = this;
        return true;