upload codes for TIZEN 2.0
[apps/home/clock.git] / clock-common / src / clock_fwk_view.c
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *    http://www.tizenopensource.org/license
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include "clock_fwk_view.h"
20 /**********************************************************************
21 ******************define, struct ,typedef, union, enum, global val *************************************
22 ***********************************************************************/
23 #define MAX_VIEWNODE_NUM    15
24
25 typedef struct _ClkViewNode {
26         clk_view *view;
27         clk_view *topview;
28 } ClkViewNode;
29
30 /**********************************************************************
31 ******************Global val , static global val*************************************
32 ***********************************************************************/
33
34 static clk_view *g_cur_view;;   //use by 'End Key' process
35 static ClkViewNode g_view_node_table[MAX_VIEWNODE_NUM];
36 static int g_view_node_table_cur_size = 0;
37
38 /**********************************************************************
39 ******************Global function ref*************************************
40 ***********************************************************************/
41 //
42 int clk_view_node_set_cur_view(clk_view * view)
43 {
44         g_cur_view = view;
45         return SUCCESS;
46 }
47
48 //
49 int clk_view_node_table_intialize()
50 {
51         g_cur_view = NULL;
52         g_view_node_table_cur_size = 0;
53         return SUCCESS;
54 }
55
56 //
57 int clk_view_node_table_register(clk_view * view, clk_view * topview)
58 {
59         if (g_view_node_table_cur_size >= MAX_VIEWNODE_NUM) {
60                 return FAILED;
61         }
62
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++;
66         return SUCCESS;
67 }
68
69 //
70 int clk_view_cb_at_endKey(void *cb)
71 {
72         int idx = 0;
73         ClkViewNode *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]);
77                         break;
78                 }
79         }
80         if (viewnode && viewnode->view && viewnode->topview) {
81                 clk_view_change(viewnode->view, viewnode->topview, cb);
82         }
83         return SUCCESS;
84 }
85
86 /**
87 * send
88 * This function is  used to be default cb in the elm_popup when get signle:"response"
89 * @param            data[in]   pointer to data
90 * @return           when success, return SUCCESS or FAILED if error
91 * @exception
92 */
93 int clk_view_create(clk_view * view, void *cb)
94 {
95         int nErr = SUCCESS;
96         int ret = SUCCESS;
97         CLK_RETVM_IF(!cb, FAILED, "cb==null");
98         CLK_RETVM_IF(!view, FAILED, "view==null");
99         if (view->create) {
100                 ret = view->create(cb);
101         }
102  End:
103         return ret;
104 }
105
106 /**
107 * send
108 * This function is  used to be default cb in the elm_popup when get signle:"response"
109 * @param            data[in]   pointer to data
110 * @return           when success, return SUCCESS or FAILED if error
111 * @exception
112 */
113 int clk_view_destroy(clk_view * view, void *cb)
114 {
115         int nErr = SUCCESS;
116         int ret = SUCCESS;
117         CLK_RETVM_IF(!cb, FAILED, "cb==null");
118         CLK_RETVM_IF(!view, FAILED, "view==null");
119         if (view->destroy) {
120                 ret = view->destroy(cb);
121         }
122  End:
123         return ret;
124 }
125
126 /**
127 * send
128 * This function is  used to be default cb in the elm_popup when get signle:"response"
129 * @param            data[in]   pointer to data
130 * @return           when success, return SUCCESS or FAILED if error
131 * @exception
132 */
133 int clk_view_update(clk_view * view, void *cb)
134 {
135         int nErr = SUCCESS;
136         int ret = SUCCESS;
137         CLK_FUN_BEG();
138         CLK_RETVM_IF(!cb, FAILED, "cb==null");
139         CLK_RETVM_IF(!view, FAILED, "view==null");
140         if (view && view->update) {
141                 ret = view->update(cb);
142         }
143  End:
144         CLK_FUN_END();
145         return ret;
146 }
147
148 /**
149 * send
150 * This function is  used to be default cb in the elm_popup when get signle:"response"
151 * @param            data[in]   pointer to data
152 * @return           when success, return SUCCESS or FAILED if error
153 * @exception
154 */
155 int clk_view_cleanup(clk_view * view, void *cb)
156 {
157         int nErr = SUCCESS;
158         int ret = SUCCESS;
159         CLK_FUN_BEG();
160         CLK_RETVM_IF(!cb, FAILED, "cb==null");
161         CLK_RETVM_IF(!view, FAILED, "view==null");
162         if (view->cleanup) {
163                 ret = view->cleanup(cb);
164         }
165  End:
166         CLK_FUN_END();
167         return ret;
168 }
169
170 /**
171 * send
172 * This function is  used to be default cb in the elm_popup when get signle:"response"
173 * @param            data[in]   pointer to data
174 * @return           when success, return SUCCESS or FAILED if error
175 * @exception
176 */
177 int clk_view_change(clk_view * from_view, clk_view * to_view, void *cb)
178 {
179         int nErr = SUCCESS;
180         int ret = SUCCESS;
181         CLK_RETVM_IF(!cb, FAILED, "cb==null");
182         CLK_RETVM_IF(!from_view, FAILED, "from_view==null");
183         CLK_RETVM_IF(!to_view, FAILED, "to_view==null");
184         CLK_FUN_BEG();
185         if (from_view->layer >= to_view->layer) {       //high layer->low layer, destroy high layer
186                 nErr = clk_view_destroy(from_view, cb);
187                 CLK_RETVM_IF(ret != SUCCESS, FAILED, "clk_view_destroy error");
188         } else {                //low layer->high layer, clean low layer
189                 nErr = clk_view_cleanup(from_view, cb);
190                 CLK_RETVM_IF(ret != SUCCESS, FAILED, "clk_view_cleanup error");
191         }
192         if (EINA_TRUE == to_view->is_create) {
193                 ret = clk_view_update(to_view, cb);
194         } else {
195                 ret = clk_view_create(to_view, cb);
196         }
197         g_cur_view = to_view;   //compute new value of g_cur_view.
198  End:
199         CLK_FUN_END();
200         return ret;
201 }