3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.tizenopensource.org/license
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.
18 #include <FUiAnimVisualElementPropertyAnimation.h>
20 #include "FormManager.h"
21 #include "EventListenerForm.h"
23 using namespace Osp::App;
24 using namespace Osp::Graphics;
25 using namespace Osp::Ui;
26 using namespace Osp::Ui::Animations;
27 using namespace Osp::Ui::Controls;
29 EventListenerForm::EventListenerForm(void)
37 EventListenerForm::~EventListenerForm(void)
39 SetVisualElement(null);
42 __pVisualElement->Destroy();
43 __pVisualElement = null;
48 EventListenerForm::Initialize()
50 Construct(FORM_STYLE_NORMAL | FORM_STYLE_HEADER | FORM_STYLE_FOOTER | FORM_STYLE_INDICATOR);
52 SetFormBackEventListener(this);
58 EventListenerForm::OnInitializing(void)
62 Header* pHeader = Form::GetHeader();
63 pHeader->SetStyle(HEADER_STYLE_TITLE);
64 pHeader->SetTitleText(L"Event Listener");
66 __pVisualElement = new (std::nothrow) VisualElement();
67 __pVisualElement->Construct();
68 __pVisualElement->SetName(L"VisualElement");
69 __pVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f));
70 __pVisualElement->SetClipChildrenEnabled(false);
71 __pVisualElement->SetShowState(true);
72 SetVisualElement(__pVisualElement);
73 Rectangle clientRect = GetClientAreaBounds();
75 __pButton = new (std::nothrow) Button();
76 __pButton->Construct(Rectangle(50, clientRect.height - 125, clientRect.width - 100, 75));
77 __pButton->SetText(L"Detached with opacity 1.0");
78 AddControl(*__pButton);
80 float redSize = 250.f;
82 __pRed = new (std::nothrow) VisualElement();
84 __pRed->SetName(L"Red");
85 __pRed->SetBounds(FloatRectangle((clientRect.width - redSize) / 2.0f, clientRect.y + (clientRect.height - redSize) / 2.0f, redSize, redSize));
86 __pRed->SetShowState(true);
87 __pRed->SetVisualElementEventListener(this);
88 __pVisualElement->AttachChild(*__pRed);
90 Canvas* pCanvas = __pRed->GetCanvasN();
91 pCanvas->FillRectangle(Color::GetColor(COLOR_ID_RED), Rectangle(0, 0, 250, 250));
94 float yellowSize = 100.f;
96 __pYellow = new VisualElement();
97 __pYellow->Construct();
98 __pYellow->SetName(L"Yellow");
99 __pYellow->SetBounds(FloatRectangle((clientRect.width - yellowSize) / 2.0f, clientRect.y + 50.0f, yellowSize, yellowSize));
100 __pYellow->SetShowState(true);
101 __pYellow->SetImplicitAnimationEnabled(false);
102 __pVisualElement->AttachChild(*__pYellow);
104 pCanvas = __pYellow->GetCanvasN();
105 pCanvas->FillRectangle(Color::GetColor(COLOR_ID_YELLOW), Rectangle(0, 0, 250, 250));
108 __detachRect = __pYellow->GetBounds();
109 __attachRect = FloatRectangle(50.0f, 50.0f, __detachRect.width, __detachRect.height);
115 EventListenerForm::OnActionPerformed(const Control& source, int actionId)
119 case ID_FOOTER_BUTTON_ATTACH_DETACH:
121 if (__bAttached == true)
123 __pRed->DetachChild(*__pYellow);
124 __pVisualElement->AttachChild(*__pYellow);
128 __pVisualElement->DetachChild(*__pYellow);
129 __pRed->AttachChild(*__pYellow);
140 EventListenerForm::OnFormBackRequested(Osp::Ui::Controls::Form& source)
142 Frame* pFrame = UiApp::GetInstance()->GetFrameAt(0);
145 FormManager* pFormManager = static_cast<FormManager*>(pFrame->GetControl(L"FormManager"));
147 if (pFormManager != null)
149 pFormManager->SendUserEvent(FormManager::REQUEST_ID_MAIN_FORM, null);
155 EventListenerForm::InitializeFooter(void)
157 Footer* pFooter = Form::GetFooter();
159 pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
160 pFooter->SetBackButton();
161 pFooter->AddActionEventListener(*this);
163 FooterItem footerItem1;
164 footerItem1.Construct(ID_FOOTER_BUTTON_ATTACH_DETACH);
165 footerItem1.SetText(L"Attach/Detach");
167 pFooter->AddItem(footerItem1);
171 EventListenerForm::OnChildAttached(VisualElement& source, VisualElement& child)
173 child.SetBounds(__attachRect);
174 child.SetOpacity(0.5f);
176 __pButton->SetText(L"Attached with opacity 0.5");
183 EventListenerForm::OnChildDetached(VisualElement& source, VisualElement& child)
185 child.SetBounds(__detachRect);
186 child.SetOpacity(1.0f);
188 __pButton->SetText(L"Detached with opacity 1.0");