4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
6 * Contact: MyoungJune Park <mj2004.park@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
21 #include <setting-common-view.h>
23 #include <Elementary.h>
25 #include <setting-common-data-error.h>
26 #include <setting-debug.h>
28 #define MAX_VIEWNODE_NUM 15
29 typedef struct _SettingViewNode {
31 setting_view *topview;
33 static setting_view *g_cur_view;; /* use by 'End Key' process */
34 static SettingViewNode g_view_node_table[MAX_VIEWNODE_NUM];
35 static int g_view_node_table_cur_size = 0;
37 int setting_view_node_set_cur_view(setting_view *view)
43 setting_view *setting_view_node_get_cur_view()
48 int setting_view_node_table_intialize()
51 g_view_node_table_cur_size = 0;
56 setting_view_node_table_register(setting_view *view, setting_view *topview)
58 //SETTING_TRACE_BEGIN;
59 if (g_view_node_table_cur_size >= MAX_VIEWNODE_NUM) {
60 return SETTING_RETURN_FAIL;
63 g_view_node_table[g_view_node_table_cur_size].view = view;
64 g_view_node_table[g_view_node_table_cur_size].topview = topview;
65 g_view_node_table_cur_size++;
69 int setting_view_cb_at_endKey(void *cb)
73 SettingViewNode *viewnode = NULL;
74 for (; idx < g_view_node_table_cur_size; idx++) {
75 if (g_cur_view == g_view_node_table[idx].view) {
76 viewnode = &(g_view_node_table[idx]);
80 if (viewnode && viewnode->view && viewnode->topview) {
81 setting_view_change(viewnode->view, viewnode->topview, cb);
86 setting_view *setting_view_get_topview(setting_view *view)
89 retv_if(NULL == view, NULL);
91 SettingViewNode *viewnode = NULL;
92 for (; idx < g_view_node_table_cur_size; idx++) {
93 if (view == g_view_node_table[idx].view) {
94 viewnode = &(g_view_node_table[idx]);
98 if (viewnode && viewnode->topview) {
99 return viewnode->topview;
107 void setting_view_update_topview(setting_view *view, setting_view *topview)
110 ret_if(NULL == view);
112 SettingViewNode *viewnode = NULL;
113 for (; idx < g_view_node_table_cur_size; idx++) {
114 if (view == g_view_node_table[idx].view) {
115 viewnode = &(g_view_node_table[idx]);
120 viewnode->topview = topview;
128 int setting_view_create(setting_view *view, void *cb)
131 setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
133 int ret = SETTING_RETURN_FAIL;
135 if (!view->is_create && view->create) {//error handle:create only when the view doesn't exit
136 ret = view->create(cb);
142 int setting_view_destroy(setting_view *view, void *cb)
145 setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
147 int ret = SETTING_RETURN_FAIL;
149 if (view->is_create && view->destroy) {//error handle:destroy only when the view exits
150 ret = view->destroy(cb);
156 int setting_view_update(setting_view *view, void *cb)
159 setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
161 int ret = SETTING_RETURN_FAIL;
163 if (view->is_create && view->update) {//error handle:update only when the view exits
164 ret = view->update(cb);
170 int setting_view_cleanup(setting_view *view, void *cb)
173 setting_retvm_if(!view || !cb , SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "Invalid arguement");
175 int ret = SETTING_RETURN_FAIL;
177 if (view->is_create && view->cleanup) {//error handle:cleanup only when the view exits
178 ret = view->cleanup(cb);
185 setting_view_change(setting_view *from_view, setting_view *to_view, void *cb)
188 setting_retvm_if(!from_view || !to_view || !cb ,
189 SETTING_GENERAL_ERR_NULL_DATA_PARAMETER,
190 "Invalid arguement");
192 int ret = SETTING_RETURN_SUCCESS;
193 if (from_view == setting_view_get_topview(to_view)) {
194 //from a parent view to his child view, don't need cleanup parent view
196 //from a child view to his parent view, need cleanup child view
197 ret = setting_view_cleanup(from_view, cb);
200 if (ret == SETTING_RETURN_FAIL) {
201 return SETTING_RETURN_FAIL;
204 if (to_view->is_create == 1) {
205 ret = setting_view_update(to_view, cb);
207 ret = setting_view_create(to_view, cb);
209 g_cur_view = to_view; /* compute new value of g_cur_view. */