From: Hermet Park Date: Tue, 21 Jun 2016 05:02:32 +0000 (+0900) Subject: implemented ui_iface_viewmgr_get_view() and ui_viewmgr_get_view_by_name(). X-Git-Tag: accepted/tizen/common/20160630.152115~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F95%2F75695%2F2;p=platform%2Fcore%2Fuifw%2Fui-viewmgr.git implemented ui_iface_viewmgr_get_view() and ui_viewmgr_get_view_by_name(). also renamed an API from ui_viewmgr_get_view() to ui_viewmgr_get_view_by_idx(). and removed ui_iface_view::set_name(). Allow renaming of view is ridiculous because we expect view name is unique. So users should decide its name when they create the view instance. Change-Id: I769ded274f82cbce251fefe426555e890670095d --- diff --git a/src/include/efl/mobile/c/ui_standard_view.h b/src/include/efl/mobile/c/ui_standard_view.h index 0e0ae0a..b739280 100644 --- a/src/include/efl/mobile/c/ui_standard_view.h +++ b/src/include/efl/mobile/c/ui_standard_view.h @@ -16,9 +16,10 @@ extern "C" { * @brief A constructor for an ui_standard_view. * * @param name view name - * * @param view An ui_standard_view instance. * + * @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name(). + * * @see ui_view_destroy() */ EAPI ui_standard_view *ui_standard_view_create(const char *name); diff --git a/src/include/efl/mobile/c/ui_view.h b/src/include/efl/mobile/c/ui_view.h index 6854e79..69ce29b 100644 --- a/src/include/efl/mobile/c/ui_view.h +++ b/src/include/efl/mobile/c/ui_view.h @@ -72,6 +72,8 @@ typedef struct * * @return The ui_view instance. * + * @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name(). + * * @see ui_view_destroy() */ EAPI ui_view *ui_view_create(const char *name); @@ -222,20 +224,6 @@ EAPI const char *ui_view_transition_style_get(ui_view *view); EAPI const ui_menu *ui_view_menu_get(ui_view *view); /** - * @brief Set name of ui_view. - * - * @note A ui_view can have a unique name. Default value of the name is NULL. - * - * @param view An ui_view instance. - * @param name A new name of given @p view. - * - * @return @c true if the given @p name is available, otherwise @c false. - * - * @see ui_view_name_get() - */ -EAPI bool ui_view_name_set(ui_view *view, const char *name); - -/** * @brief Return a name of this view. * * @param view An ui_view instance. diff --git a/src/include/efl/mobile/c/ui_viewmgr.h b/src/include/efl/mobile/c/ui_viewmgr.h index 6b38a05..5360f89 100644 --- a/src/include/efl/mobile/c/ui_viewmgr.h +++ b/src/include/efl/mobile/c/ui_viewmgr.h @@ -136,7 +136,21 @@ EAPI ui_view *ui_viewmgr_last_view_get(ui_viewmgr *viewmgr); * @see ui_viewmgr_view_index_get() * @see ui_viewmgr_view_count_get() */ -EAPI ui_view *ui_viewmgr_view_get(ui_viewmgr *viewmgr, int idx); +EAPI ui_view *ui_viewmgr_view_get_by_idx(ui_viewmgr *viewmgr, int idx); + +/** + * @brief Return a view which is matched with the @p name. + * + * @note Every view have their names as their own identifiers. + * + * @param name The name of the view which you are looking for. + * + * @return The view which name is matched with @p name. + * If there were no views name matched, @c NULL will be returned. + * + * @see ui_iface_view::set_name() + */ +EAPI ui_view *ui_viewmgr_view_get_by_name(ui_viewmgr *viewmgr, const char *name); /** * @brief Get a base object of a ui_viewmgr. @@ -162,9 +176,6 @@ EAPI Evas_Object *ui_viewmgr_base_get(ui_viewmgr *viewmgr); */ EAPI int ui_viewmgr_view_index_get(ui_viewmgr *viewmgr, const ui_view *view); -//FIXME: -//ui_view *ui_viewmgr_view_get_by_id(ui_viewmgr *viewmgr, const char *id); - /** * @brief Return the number of views which this @p given viewmgr has. * diff --git a/src/include/efl/mobile/ui_view.h b/src/include/efl/mobile/ui_view.h index c7b8bdf..5ae1d94 100644 --- a/src/include/efl/mobile/ui_view.h +++ b/src/include/efl/mobile/ui_view.h @@ -40,6 +40,8 @@ public: * @brief This is a constructor for initializing this view resources. * * @param name view name. + * + * @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name() */ ui_view(const char *name = NULL); diff --git a/src/include/efl/ui_base_viewmgr.h b/src/include/efl/ui_base_viewmgr.h index 398475d..7979bda 100644 --- a/src/include/efl/ui_base_viewmgr.h +++ b/src/include/efl/ui_base_viewmgr.h @@ -154,6 +154,20 @@ public: ui_base_view *get_view(unsigned int idx); /** + * @brief Return a view which is matched with the @p name. + * + * @note Every view have their names as their own identifiers. + * + * @param name The name of the view which you are looking for. + * + * @return The view which name is matched with @p name. + * If there were no views name matched, @c NULL will be returned. + * + * @see ui_iface_view::set_name() + */ + ui_base_view *get_view(const char *name); + + /** * @brief Get a base object of this viewmgr. * * @note Normally, a base object can be used for adding additional objects. diff --git a/src/include/interface/ui_iface_view.h b/src/include/interface/ui_iface_view.h index a4fbbd4..1324431 100644 --- a/src/include/interface/ui_iface_view.h +++ b/src/include/interface/ui_iface_view.h @@ -44,6 +44,8 @@ public: * @brief This is a constructor for initializing this view resources. * * @param name view name. + * + * @warning if you don't set a view name, you could not look up the view with its name. @see ui_viewmgr_view_get_by_name() */ ui_iface_view(const char *name = NULL); @@ -67,19 +69,6 @@ public: bool set_transition_style(const char *style); /** - * @brief Set name of the view. - * - * @note A view can have a unique name. Default value of the name is NULL. - * - * @param name A new name of view. - * - * @return true if the given @c name is available, otherwise false. - * - * @warning When you override this member function, you should check the name duplicate with other view or not. - */ - bool set_name(const char *name); - - /** * @brief Set content removable. * * @param removable if @p removable is @c true, content of this view will be removed on unload state. @c false otherwise. diff --git a/src/include/interface/ui_iface_viewmgr.h b/src/include/interface/ui_iface_viewmgr.h index a52faac..0efa710 100644 --- a/src/include/interface/ui_iface_viewmgr.h +++ b/src/include/interface/ui_iface_viewmgr.h @@ -227,7 +227,7 @@ protected: * @return The view which name is matched with @p name. * If there were no views name matched, @c NULL will be returned. * - * @see ui_iface_view::set_name() + * @see ui_iface_view::get_name(). */ ui_iface_view *get_view(const char *name); diff --git a/src/lib/efl/mobile/c/ui_view.cpp b/src/lib/efl/mobile/c/ui_view.cpp index eb777ab..365986f 100644 --- a/src/lib/efl/mobile/c/ui_view.cpp +++ b/src/lib/efl/mobile/c/ui_view.cpp @@ -247,12 +247,6 @@ EAPI const ui_menu *ui_view_menu_get(ui_view *view) return view->get_menu(); } -EAPI bool ui_view_name_set(ui_view *view, const char *name) -{ - if (!validate_view(view)) return false; - return view->set_name(name); -} - EAPI const char *ui_view_name_get(ui_view *view) { if (!validate_view(view)) return NULL; diff --git a/src/lib/efl/mobile/c/ui_viewmgr.cpp b/src/lib/efl/mobile/c/ui_viewmgr.cpp index 24e9e01..3a54ca1 100644 --- a/src/lib/efl/mobile/c/ui_viewmgr.cpp +++ b/src/lib/efl/mobile/c/ui_viewmgr.cpp @@ -18,7 +18,6 @@ static bool validate_viewmgr(ui_viewmgr *viewmgr) return true; } - EAPI ui_view *ui_viewmgr_view_push(ui_viewmgr *viewmgr, ui_view *view) { if (!viewmgr || !view) @@ -82,12 +81,18 @@ EAPI ui_view *ui_viewmgr_last_view_get(ui_viewmgr *viewmgr) return dynamic_cast(viewmgr->get_last_view()); } -EAPI ui_view *ui_viewmgr_view_get(ui_viewmgr *viewmgr, int idx) +EAPI ui_view *ui_viewmgr_view_get_by_idx(ui_viewmgr *viewmgr, int idx) { if (!validate_viewmgr(viewmgr)) return NULL; return dynamic_cast(viewmgr->get_view(idx)); } +EAPI ui_view *ui_viewmgr_view_get_by_name(ui_viewmgr *viewmgr, const char *name) +{ + if (!validate_viewmgr(viewmgr)) return NULL; + return dynamic_cast(viewmgr->get_view(name)); +} + EAPI Evas_Object *ui_viewmgr_base_get(ui_viewmgr *viewmgr) { if (!validate_viewmgr(viewmgr)) return NULL; @@ -105,7 +110,6 @@ EAPI int ui_viewmgr_view_index_get(ui_viewmgr *viewmgr, const ui_view *view) return viewmgr->get_view_index(view); } - EAPI int ui_viewmgr_view_count_get(ui_viewmgr *viewmgr) { if (!validate_viewmgr(viewmgr)) return -1; diff --git a/src/lib/efl/ui_base_viewmgr.cpp b/src/lib/efl/ui_base_viewmgr.cpp index daddf2a..a5c3742 100644 --- a/src/lib/efl/ui_base_viewmgr.cpp +++ b/src/lib/efl/ui_base_viewmgr.cpp @@ -521,6 +521,11 @@ ui_base_view *ui_base_viewmgr::get_view(unsigned int idx) return dynamic_cast(ui_iface_viewmgr::get_view(idx)); } +ui_base_view *ui_base_viewmgr::get_view(const char *name) +{ + return dynamic_cast(ui_iface_viewmgr::get_view(name)); +} + ui_base_view *ui_base_viewmgr::get_last_view() { return dynamic_cast(ui_iface_viewmgr::get_last_view()); diff --git a/src/lib/interface/ui_iface_view.cpp b/src/lib/interface/ui_iface_view.cpp index bdd0c48..2d6cfb9 100644 --- a/src/lib/interface/ui_iface_view.cpp +++ b/src/lib/interface/ui_iface_view.cpp @@ -60,7 +60,6 @@ public: ~ui_iface_view_impl(); bool set_transition_style(const char *style); - bool set_name(const char *name); void set_removable_content(bool removable); void set_indicator(ui_view_indicator indicator); const char *get_transition_style(); @@ -155,12 +154,6 @@ bool ui_iface_view_impl::set_transition_style(const char *style) return true; } -bool ui_iface_view_impl::set_name(const char *name) -{ - this->name.assign(name); - return true; -} - void ui_iface_view_impl::set_removable_content(bool removable) { this->removable_content = removable; @@ -288,11 +281,6 @@ bool ui_iface_view::set_transition_style(const char *style) return this->impl->set_transition_style(style); } -bool ui_iface_view::set_name(const char *name) -{ - return this->impl->set_name(name); -} - void ui_iface_view::set_removable_content(bool removable) { this->impl->set_removable_content(removable); diff --git a/src/lib/interface/ui_iface_viewmgr.cpp b/src/lib/interface/ui_iface_viewmgr.cpp index 7c14bf3..fb5cc86 100644 --- a/src/lib/interface/ui_iface_viewmgr.cpp +++ b/src/lib/interface/ui_iface_viewmgr.cpp @@ -127,6 +127,26 @@ bool ui_iface_viewmgr_impl::need_soft_key() bool ui_iface_viewmgr_impl::connect_view(ui_iface_view *view) { + //TODO: Perform this only in debug mode? + //Check whether the same name of this view is already existed in this viewmgr? + int name_len = strlen(view->get_name()); + const char *name = view->get_name(); + + for (VIEW_ITR it = this->view_list.begin(); it != this->view_list.end(); it++) + { + ui_iface_view *view = *it; + const char *view_name = view->get_name(); + if (!view_name) continue; + int view_name_len = strlen(view_name); + + //Got you! + if ((view_name_len == name_len) && !strcmp(name, view_name)) + { + LOGE("the same name of ui_iface_view(%p) is already in this ui_iface_viewmgr(%p)", view, this); + return false; + } + } + return view->set_viewmgr(this->get_instance()); } @@ -409,7 +429,23 @@ bool ui_iface_viewmgr_impl::deactivate() ui_iface_view *ui_iface_viewmgr_impl::get_view(const char *name) { - //FIXME: ... + if (!name) return NULL; + int name_len = strlen(name); + + for (VIEW_ITR it = this->view_list.begin(); it != this->view_list.end(); it++) + { + ui_iface_view *view = *it; + const char *view_name = view->get_name(); + if (!view_name) continue; + int view_name_len = strlen(view_name); + + //Got you! + if ((view_name_len == name_len) && !strcmp(name, view_name)) + { + return view; + } + } + return NULL; }