The license change version 1.0 to version 1.1
[apps/home/wrt-setting.git] / webapp-common / view.cpp
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
4   * Licensed under the Flora License, Version 1.1 (the "License");
5   * you may not use this file except in compliance with the License.
6   * You may obtain a copy of the License at
7   *
8   *     http://floralicense.org/license/
9   *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16
17 #include <Evas.h>
18
19 #include <dpl/assert.h>
20
21 #include "view.h"
22
23 namespace WebAppCommonSetting {
24
25 void delCb(void *data,
26         Evas */*e*/,
27         Evas_Object */*eo*/,
28         void */*event_info*/)
29 {
30     View *v;
31
32     v = static_cast<View *>(data);
33     Assert(v);
34     v->resetBase();
35     v->invokeUnloadCb();
36 }
37
38 void View::resetBase(Evas_Object *base)
39 {
40     if (m_base)
41         evas_object_event_callback_del_full(m_base, EVAS_CALLBACK_DEL, delCb, this);
42
43     m_base = base;
44
45     if (m_base)
46         evas_object_event_callback_add(base, EVAS_CALLBACK_DEL, delCb, this);
47 }
48
49 void View::setUnloadCb(ViewUnloadCb cb, void *data)
50 {
51     m_viewUnloadCb = cb;
52     m_viewUnloadCbData = data;
53 }
54
55 void View::unsetUnloadCb(void)
56 {
57     m_viewUnloadCb = NULL;
58     m_viewUnloadCbData = NULL;
59 }
60
61 void View::invokeUnloadCb(void)
62 {
63     if (m_viewUnloadCb)
64         m_viewUnloadCb(m_viewUnloadCbData);
65 }
66
67 View::~View(void)
68 {
69     unsetUnloadCb();
70
71     if (m_base) {
72         evas_object_event_callback_del_full(m_base, EVAS_CALLBACK_DEL, delCb, this);
73         evas_object_del(m_base);
74     }
75 }
76
77 } /* WebAppCommonSetting */