Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / EffectsApp / EffectsApp / project / src / MainForm.cpp
1 //
2 // Open Service Platform
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 #include "FormManager.h"
18 #include "MainForm.h"
19
20 using namespace Osp::App;
21 using namespace Osp::Base;
22 using namespace Osp::Graphics;
23 using namespace Osp::Ui;
24 using namespace Osp::Ui::Controls;
25
26 MainForm::MainForm(void)
27 {
28 }
29
30 MainForm::~MainForm(void)
31 {
32 }
33
34 bool
35 MainForm::Initialize()
36 {
37         Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
38         SetFormBackEventListener(this);
39
40         return true;
41 }
42
43 result
44 MainForm::OnInitializing(void)
45 {
46         result r = E_SUCCESS;
47         __pHeader = GetHeader();
48         __pHeader->SetTitleText(L"EffectsApp");
49
50         Footer* pFooter = Form::GetFooter();
51
52         pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
53         pFooter->SetBackButton();
54
55         __listViewMainMenuNameArray[0] = L"Interactive effect";
56         __listViewMainMenuNameArray[1] = L"Time based single effect";
57
58         __pListViewMainMenu = new ListView();
59         __pListViewMainMenu->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, false);
60         __pListViewMainMenu->SetItemProvider(*this);
61         __pListViewMainMenu->AddListViewItemEventListener(*this);
62         AddControl(*__pListViewMainMenu);
63
64         return r;
65 }
66
67 result
68 MainForm::OnTerminating(void)
69 {
70         result r = E_SUCCESS;
71
72         return r;
73 }
74
75 void
76 MainForm::OnFormBackRequested(Osp::Ui::Controls::Form& source)
77 {
78         UiApp* pApp = UiApp::GetInstance();
79         AppAssert(pApp);
80         pApp->Terminate();
81 }
82
83 int
84 MainForm::GetItemCount(void)
85 {
86         return LIST_VIEW_MAIN_MENU_COUNT;
87 }
88
89 Osp::Ui::Controls::ListItemBase*
90 MainForm::CreateItem(int index, int itemWidth)
91 {
92         SimpleItem* pItem = new SimpleItem();
93         pItem->Construct(Osp::Graphics::Dimension(itemWidth, 100), LIST_ANNEX_STYLE_NORMAL);
94         pItem->SetElement(__listViewMainMenuNameArray[index], null);
95
96         return pItem;
97 }
98
99 bool
100 MainForm::DeleteItem(int index, Osp::Ui::Controls::ListItemBase *pItem, int itemWidth)
101 {
102         delete pItem;
103         pItem = null;
104         return true;
105 }
106
107 void
108 MainForm::OnListViewItemStateChanged(ListView &listView, int index, int elementId, ListItemStatus status)
109 {
110         Frame* pFrame = UiApp::GetInstance()->GetFrameAt(0);
111         if (pFrame != null)
112         {
113                 FormManager* pFormManager = static_cast<FormManager*>(pFrame->GetControl(L"FormManager"));
114
115                 if (pFormManager != null)
116                 {
117                         switch (index)
118                         {
119                         case 0:
120                                 pFormManager->SendUserEvent(FormManager::REQUEST_ID_INTERACTIVE_PHYSICS_EFFECT_FORM, null);
121                                 break;
122                         case 1:
123                                 pFormManager->SendUserEvent(FormManager::REQUEST_ID_TIME_BASED_SINGLE_EFFECT_FORM, null);
124                                 break;
125                         }
126                 }
127         }
128 }