Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / cpp / Sample / Tizen C++ / SceneManagement / SceneManagement / project / src / ComplexForm.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 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 #include "ComplexForm.h"
19 #include "SceneRegister.h"
20
21 using namespace Osp::Base;
22 using namespace Osp::Ui;
23 using namespace Osp::Ui::Controls;
24 using namespace Osp::Ui::Scenes;
25 using namespace Osp::Base::Collection;
26
27
28 static const int ID_BUTTON_NEXT_CHAPTER = 101;
29 static const int ID_BUTTON_HELP = 102;
30 static const int ID_BUTTON_GO_MAIN_MENU = 103;
31 static const int ID_HEADER_BUTTON_LEFT = 110;
32 static const int ID_HEADER_BUTTON_RIGHT = 111;
33
34
35 ComplexForm::ComplexForm(void)
36 {
37 }
38
39 ComplexForm::~ComplexForm(void)
40 {
41 }
42
43 bool
44 ComplexForm::Initialize(void)
45 {
46         Form::Construct(L"IDF_COMPLEX_FORM");
47
48         return true;
49 }
50
51 result
52 ComplexForm::OnInitializing(void)
53 {
54         result r = E_SUCCESS;
55
56         // Setup header
57         Header* pHeader = GetHeader();
58         AppAssert(pHeader)
59         ButtonItem buttonItem;
60         buttonItem.Construct(BUTTON_ITEM_STYLE_TEXT, ID_HEADER_BUTTON_LEFT);
61         buttonItem.SetText(L"Info");
62         pHeader->SetButton(BUTTON_POSITION_LEFT, buttonItem);
63         buttonItem.SetActionId(ID_HEADER_BUTTON_RIGHT);
64         buttonItem.SetText(L"Log");
65         pHeader->SetButton(BUTTON_POSITION_RIGHT, buttonItem);
66         pHeader->AddActionEventListener(*this);
67
68         // Setup footer
69         Footer* pFooter = GetFooter();
70         AppAssert(pFooter)
71         pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
72         pFooter->SetBackButton();
73         pFooter->AddActionEventListener(*this);
74
75         SetFormBackEventListener(this);
76
77         // Button setup
78         Button* pButton = static_cast<Button*>(GetControl("IDC_BUTTON_NEXT_CHAPTER"));
79         AppAssert(pButton)
80         pButton->SetActionId(ID_BUTTON_NEXT_CHAPTER);
81         pButton->AddActionEventListener(*this);
82
83         pButton = static_cast<Button*>(GetControl("IDC_BUTTON_HELP"));
84         AppAssert(pButton)
85         pButton->SetActionId(ID_BUTTON_HELP);
86         pButton->AddActionEventListener(*this);
87
88         pButton = static_cast<Button*>(GetControl("IDC_BUTTON_GO_MAIN_MENU"));
89         AppAssert(pButton)
90         pButton->SetActionId(ID_BUTTON_GO_MAIN_MENU);
91         pButton->AddActionEventListener(*this);
92
93         return r;
94 }
95
96 result
97 ComplexForm::OnTerminating(void)
98 {
99         result r = E_SUCCESS;
100
101         return r;
102 }
103
104 void
105 ComplexForm::OnSceneActivatedN(const Osp::Ui::Scenes::SceneId& previousSceneId,
106                                                            const Osp::Ui::Scenes::SceneId& currentSceneId, Osp::Base::Collection::IList* pArgs)
107 {
108         // Replace title to scene name
109         Header* pHeader = GetHeader();
110         AppAssert(pHeader);
111         pHeader->SetTitleText(currentSceneId);
112
113         // Set next button text
114         Button* pButton = static_cast<Button*>(GetControl("IDC_BUTTON_NEXT_CHAPTER"));
115         AppAssert(pButton)
116         pButton->SetText((currentSceneId == SCENE_COMPLEX_4) ? L"Back To Chapter 1" : L"Next Chapter >");
117
118         String chapterDescription;
119         if (currentSceneId == SCENE_COMPLEX_1)
120         {
121                 chapterDescription = L"Chapter 1.\n\nWelcome to Scene Management.\n\nScene is combination of Form + Panel control.";
122         }
123         else if (currentSceneId == SCENE_COMPLEX_2)
124         {
125                 chapterDescription = L"Chapter 2.\n\nPrepare FormFactory and PanelFactory.\n\nRegister a Scene to SceneManager.";
126         }
127         else if (currentSceneId == SCENE_COMPLEX_3)
128         {
129                 chapterDescription = L"Chapter 3.\n\nScene navigation with GoFoward() and GoBackward()."
130                                                          L"\n\nGet callback with Scene event listener and Scene manager event listener.";
131         }
132         else if (currentSceneId == SCENE_COMPLEX_4)
133         {
134                 chapterDescription = L"Chapter 4.\n\nThe more!\n\nSceneTransitionPolicyProvider and SceneAnimationProvider.";
135         }
136         else
137         {
138                 chapterDescription = L"Is error case?";
139         }
140
141         TextBox* pTextBox = static_cast<TextBox*>(GetControl("IDC_TEXTBOX_MESSAGE"));
142         AppAssert(pTextBox)
143         pTextBox->SetText(chapterDescription);
144 }
145
146 void
147 ComplexForm::OnSceneDeactivated(const Osp::Ui::Scenes::SceneId& currentSceneId,
148                                                                 const Osp::Ui::Scenes::SceneId& nextSceneId)
149 {
150
151 }
152
153 void
154 ComplexForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
155 {
156         SceneManager* pSceneManager = SceneManager::GetInstance();
157         AppAssert(pSceneManager);
158         SceneId currentSceneId = pSceneManager->GetCurrentSceneId();
159
160         switch (actionId)
161         {
162         case ID_HEADER_BUTTON_LEFT:
163                 pSceneManager->GoForward(ForwardSceneTransition(SCENE_INFORMATION));
164                 break;
165
166         case ID_HEADER_BUTTON_RIGHT:
167                 pSceneManager->GoForward(ForwardSceneTransition(SCENE_LOG));
168                 break;
169
170         case ID_BUTTON_NEXT_CHAPTER:
171                 if (currentSceneId == SCENE_COMPLEX_4)
172                 {
173                         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_COMPLEX_1, SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT));
174                 }
175                 else
176                 {
177                         // GoForward via SceneTransitionPolicyProvider's scenario.
178                         pSceneManager->GoForward(ForwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
179                 }
180                 break;
181
182         case ID_BUTTON_HELP:
183                 pSceneManager->GoForward(ForwardSceneTransition(SCENE_HELP));
184                 break;
185
186         case ID_BUTTON_GO_MAIN_MENU:
187                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_MAIN_MENU, (currentSceneId == SCENE_COMPLEX_1) ?
188                                                                         SCENE_TRANSITION_ANIMATION_TYPE_RIGHT : SCENE_TRANSITION_ANIMATION_TYPE_ZOOM_OUT));
189                 break;
190         }
191 }
192
193 void
194 ComplexForm::OnFormBackRequested(Osp::Ui::Controls::Form& source)
195 {
196         SceneManager* pSceneManager = SceneManager::GetInstance();
197         AppAssert(pSceneManager);
198         pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
199 }