3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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://floralicense.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.
24 #include "MultiForm.h"
25 #include "AppConfig.h"
27 #include "Image/GifDecoderForm.h"
28 #include "Image/ImageViewerForm.h"
29 #include "Image/ImageConverterForm.h"
30 #include "Image/ImageColorConvertForm.h"
31 #include "Image/ImageFlipRotateForm.h"
32 #include "Image/ImageResizeForm.h"
34 #include "Audio/AudioInOut.h"
35 #include "Audio/TonePlayerForm.h"
36 #include "Audio/AudioEqualizerForm.h"
37 #include "Audio/GlesCubePlayer.h"
39 #include "Recorder/AudioRecorderForm.h"
40 #include "Recorder/VideoRecorderForm.h"
42 #include "Camera/CameraCaptureForm.h"
44 #include "Codec/AudioDecoderForm.h"
45 #include "Codec/AudioEncoderForm.h"
46 #include "Codec/VideoDecoderForm.h"
47 #include "Codec/VideoEncoderForm.h"
48 #include "Codec/VideoFrameExtractorForm.h"
50 #include "Player/CameraPlayerForm.h"
51 #include "Player/CaptureVideoForm.h"
52 #include "Player/MultiPlayForm.h"
53 #include "Player/PlayerForm.h"
54 #include "Player/VideoRecorderPlayerForm.h"
56 #include "MediaPlayerForm.h"
58 using namespace Tizen::Ui;
59 using namespace Tizen::Ui::Controls;
60 using namespace Tizen::Ui::Scenes;
62 static const int ERROR_MESSAGE_POPUP_WIDTH = 470;
63 static const int ERROR_MESSAGE_POPUP_HEIGHT = 480;
65 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH = 470;
66 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT = 400;
68 static const int ERROR_MESSAGE_POPUP_BUTTON_W = 100;
69 static const int ERROR_MESSAGE_POPUP_BUTTON_H = 60;
71 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W = 100;
72 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H = 60;
74 static const int ERROR_MESSAGE_POPUP_LABEL_TEXT_FONT = 30;
76 using namespace Tizen::Base;
77 using namespace Tizen::Base::Collection;
78 using namespace Tizen::Ui::Controls;
79 using namespace Tizen::Graphics;
80 using namespace Tizen::App;
83 HashMap* MultiForm::_pSceneProcMap = null;
85 extern void* pMainMediaAppFrame;
87 MultiForm::MultiForm(void)
88 : _pFrame( (Tizen::Ui::Controls::Frame*) pMainMediaAppFrame),
90 _isProcessedEvent(false),
91 _pErrorMessagePopup(null),
100 MultiForm::~MultiForm(void)
105 MultiForm::Construct(Tizen::Base::String resourceId)
107 result r = E_SUCCESS;
109 _pConfig = AppConfig::GetInstance();
111 r = Form::Construct(resourceId);
112 TryCatch(r == E_SUCCESS, , "Form::Construct %s", GetErrorMessage(r));
114 SetFormBackEventListener(this);
115 AddOrientationEventListener(*this);
122 MultiForm::OnInitializing(void)
129 MultiForm::Activate(void* pParam)
135 MultiForm::GetFormProc(Tizen::Base::String formId)
137 result r = E_SUCCESS;
140 if (_pSceneProcMap == null)
145 r = _pSceneProcMap->ContainsKey(formId, out);
147 if (!IsFailed(r) || out == true)
150 r = _pSceneProcMap->ContainsKey(formId, out);
151 TryCatch(r == E_SUCCESS && out == true, , "pSceneProcMap.ContainesKey failed:%s, %ls", GetErrorMessage(r), formId.GetPointer());
152 Integer* pInt = (Integer*) _pSceneProcMap->GetValue(formId);
153 TryCatch(pInt != null, , "pSceneProcMap->GetValue(%ls) is null", formId.GetPointer());
154 MultiFormCreateProc proc = (MultiFormCreateProc) pInt->ToInt();
171 MultiForm::RegisterAllScenes()
173 result r = E_SUCCESS;
175 r = MultiForm::SceneRegister(MainForm::GetFormId(), MainForm::GetSceneId(), MainForm::FormCreateFunc);
176 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
178 // Audio scenes registration
179 r = MultiForm::SceneRegister(AudioInOut::GetFormId(), AudioInOut::GetSceneId(), AudioInOut::FormCreateFunc);
180 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
182 r = MultiForm::SceneRegister(TonePlayerForm::GetFormId(), TonePlayerForm::GetSceneId(), TonePlayerForm::FormCreateFunc);
183 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
185 r = MultiForm::SceneRegister(AudioEqualizerForm::GetFormId(), AudioEqualizerForm::GetSceneId(), AudioEqualizerForm::FormCreateFunc);
\r
186 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
188 r = MultiForm::SceneRegister(GlesCubePlayerForm::GetFormId(), GlesCubePlayerForm::GetSceneId(), GlesCubePlayerForm::FormCreateFunc);
189 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
191 // camera scenes registration
192 r = MultiForm::SceneRegister(CameraCaptureForm::GetFormId(), CameraCaptureForm::GetSceneId(), CameraCaptureForm::FormCreateFunc);
193 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
195 // Codec scenes registration
196 r = MultiForm::SceneRegister(AudioDecoderForm::GetFormId(), AudioDecoderForm::GetSceneId(), AudioDecoderForm::FormCreateFunc);
197 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
199 r = MultiForm::SceneRegister(AudioEncoderForm::GetFormId(), AudioEncoderForm::GetSceneId(), AudioEncoderForm::FormCreateFunc);
200 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
202 r = MultiForm::SceneRegister(VideoDecoderForm::GetFormId(), VideoDecoderForm::GetSceneId(), VideoDecoderForm::FormCreateFunc);
203 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
205 r = MultiForm::SceneRegister(VideoEncoderForm::GetFormId(), VideoEncoderForm::GetSceneId(), VideoEncoderForm::FormCreateFunc);
206 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
208 r = MultiForm::SceneRegister(VideoFrameExtractorForm::GetFormId(), VideoFrameExtractorForm::GetSceneId(), VideoFrameExtractorForm::FormCreateFunc);
209 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
212 // Image scenes registration
213 r = MultiForm::SceneRegister(GifDecoderForm::GetFormId(), GifDecoderForm::GetSceneId(), GifDecoderForm::FormCreateFunc);
214 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
216 r = MultiForm::SceneRegister(ImageColorConvertForm::GetFormId(), ImageColorConvertForm::GetSceneId(), ImageColorConvertForm::FormCreateFunc);
217 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
219 r = MultiForm::SceneRegister(ImageConverterForm::GetFormId(), ImageConverterForm::GetSceneId(), ImageConverterForm::FormCreateFunc);
220 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
222 r = MultiForm::SceneRegister(ImageFlipRotateForm::GetFormId(), ImageFlipRotateForm::GetSceneId(), ImageFlipRotateForm::FormCreateFunc);
223 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
225 r = MultiForm::SceneRegister(ImageResizeForm::GetFormId(), ImageResizeForm::GetSceneId(), ImageResizeForm::FormCreateFunc);
226 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
228 r = MultiForm::SceneRegister(ImageViewerForm::GetFormId(), ImageViewerForm::GetSceneId(), ImageViewerForm::FormCreateFunc);
229 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
232 // Player scenes registration
233 r = MultiForm::SceneRegister(CameraPlayerForm::GetFormId(), CameraPlayerForm::GetSceneId(), CameraPlayerForm::FormCreateFunc);
234 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
236 r = MultiForm::SceneRegister(CaptureVideoForm::GetFormId(), CaptureVideoForm::GetSceneId(), CaptureVideoForm::FormCreateFunc);
237 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
239 r = MultiForm::SceneRegister(MultiPlayForm::GetFormId(), MultiPlayForm::GetSceneId(), MultiPlayForm::FormCreateFunc);
240 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
242 r = MultiForm::SceneRegister(PlayerForm::GetFormId(), PlayerForm::GetSceneId(), PlayerForm::FormCreateFunc);
243 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
245 r = MultiForm::SceneRegister(VideoRecorderPlayerForm::GetFormId(), VideoRecorderPlayerForm::GetSceneId(), VideoRecorderPlayerForm::FormCreateFunc);
246 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
249 // Recorder scenes registration
250 r = MultiForm::SceneRegister(AudioRecorderForm::GetFormId(), AudioRecorderForm::GetSceneId(), AudioRecorderForm::FormCreateFunc);
251 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
253 r = MultiForm::SceneRegister(VideoRecorderForm::GetFormId(), VideoRecorderForm::GetSceneId(), VideoRecorderForm::FormCreateFunc);
254 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
257 // MediaPlayer scenes registration
258 r = MultiForm::SceneRegister(MediaPlayerForm::GetFormId(), MediaPlayerForm::GetSceneId(), MediaPlayerForm::FormCreateFunc);
259 TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
264 MultiForm::SceneRegister(const Tizen::Base::String& formId, const Tizen::Ui::Scenes::SceneId& sceneId, MultiFormCreateProc proc)
267 result r = E_SUCCESS;
268 SceneManager* pSceneManager = SceneManager::GetInstance();
270 if (_pSceneProcMap == null)
272 _pSceneProcMap = new (std::nothrow) HashMap();
273 _pSceneProcMap->Construct();
275 r = _pSceneProcMap->ContainsKey(formId, out);
276 TryCatch(r == E_SUCCESS, , "_pSceneProcMap.ContainsKey failed : %s", GetErrorMessage(r));
279 r = _pSceneProcMap->SetValue(*(new String(formId)), *(new Integer((int) (proc))));
283 r = _pSceneProcMap->Add(*(new String(formId)), *(new Integer((int) (proc))));
285 TryCatch(r == E_SUCCESS, , "procMap->SetValue or Add failed : %s %d %ls, %x", GetErrorMessage(r), out, formId.GetPointer(), proc);
286 pSceneManager->RegisterScene(sceneId,formId, L"");
294 MultiForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
299 MultiForm::OnClientDeactivated(MultiForm* pForm, void* pParam)
304 MultiForm::Deactivate(void)
310 MultiForm::OnDeactivate(void)
312 SceneManager* pSceneManager = SceneManager::GetInstance();
313 pSceneManager->GoBackward(BackwardSceneTransition());
317 MultiForm::OnForeground(void)
322 MultiForm::OnBackground(void)
327 MultiForm::OnLowMemory(void)
332 MultiForm::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
337 MultiForm::OnScreenOn(void)
342 MultiForm::OnScreenOff(void)
347 MultiForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
353 MultiForm::OnKeyPressed(Tizen::Ui::Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
355 AppLog("Here - %d", keyEventInfo.GetKeyCode());
356 if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
358 if (_pErrorMessagePopup != null)
360 _pErrorMessagePopup->RemoveAllControls();
361 _pErrorMessagePopup->SetShowState(false);
362 AppLog(" Removing the control");
363 SAFE_DELETE(_pErrorMessagePopup);
364 _isProcessedEvent = true;
365 _inErrorState = false;
373 MultiForm::ShowErrorMessagePopup(String filePath, String Class, const char* pMethod, result r, const char* pSrcfileName, int lineNo, String errorMsg)
376 int orientationStatus = 0;
377 Rectangle popupLableRect;
381 if (_inErrorState == true)
383 AppLog("Already in the error state");
386 _inErrorState = true;
387 _isProcessedEvent = false;
389 AppLog("MultiForm::ShowErrorMessagePopup\n");
390 orientationStatus = GetOrientationStatus();
391 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
392 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
394 _pErrorMessagePopup = new (std::nothrow) Popup;
395 if (_pErrorMessagePopup == null)
399 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
400 _pErrorMessagePopup->SetTitleText(L"Error");
402 _pErrorMessagePopupLabel = new (std::nothrow) Label;
403 if (_pErrorMessagePopupLabel == null)
408 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
410 popupLableRect.x = 0;
411 popupLableRect.y = 0;
413 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
414 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
416 _pErrorMessagePopupBtn = new (std::nothrow) Button;
417 if (_pErrorMessagePopupBtn == null)
422 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
423 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
425 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
426 ERROR_MESSAGE_POPUP_BUTTON_W,
427 ERROR_MESSAGE_POPUP_BUTTON_H),
429 _pErrorMessagePopupBtn->SetActionId(ID_BUTTON_ERROR_POPUP_OK);
430 _pErrorMessagePopupBtn->AddActionEventListener(*this);
431 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
436 _pErrorMessagePopup = new (std::nothrow) Popup;
437 if (_pErrorMessagePopup == null)
441 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
442 _pErrorMessagePopup->SetTitleText(L"Error");
444 _pErrorMessagePopupLabel = new (std::nothrow) Label;
445 if (_pErrorMessagePopupLabel == null)
450 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
452 popupLableRect.x = 0;
453 popupLableRect.y = 0;
455 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
456 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
458 _pErrorMessagePopupBtn = new (std::nothrow) Button;
459 if (_pErrorMessagePopupBtn == null)
464 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W/2);
465 yPos = ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H;
467 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
469 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
470 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
471 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
473 _pErrorMessagePopupBtn->SetActionId(ID_BUTTON_ERROR_POPUP_OK);
474 _pErrorMessagePopupBtn->AddActionEventListener(*this);
475 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
478 _pErrorMessagePopup->SetShowState(true);
480 errorMessage.Append(L"Path:");
481 errorMessage.Append(filePath);
482 errorMessage.Append('\n');
483 errorMessage.Append(L"Class:");
484 errorMessage.Append(Class);
485 errorMessage.Append('\n');
486 errorMessage.Append(L"Method:");
487 errorMessage.Append(pMethod);
488 errorMessage.Append('\n');
489 errorMessage.Append(L"Error:");
490 if (errorMsg.GetLength() != 0)
492 errorMessage.Append(errorMsg);
496 errorMessage.Append(GetErrorMessage(r));
498 errorMessage.Append('\n');
499 errorMessage.Append(L"File:");
500 errorMessage.Append(pSrcfileName);
501 errorMessage.Append('\n');
502 errorMessage.Append(L"Line:");
503 errorMessage.Append(lineNo);
504 errorMessage.Append('\n');
506 _pErrorMessagePopup->SetPropagatedKeyEventListener(this);
507 _pErrorMessagePopupLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
508 _pErrorMessagePopupLabel->SetTextConfig(ERROR_MESSAGE_POPUP_LABEL_TEXT_FONT, LABEL_TEXT_STYLE_NORMAL);
509 _pErrorMessagePopupLabel->SetText(errorMessage);
510 _pErrorMessagePopupLabel->RequestRedraw();
512 r = _pErrorMessagePopup->Show();
513 AppLog("_pErrorMessagePopup Show: %s\n", GetErrorMessage(r));
517 AppLog("_pErrorMessagePopup Show failed due to OUT_OF_MEMORY");
521 MultiForm::ShowMessagePopup(const char* pMessage, unsigned int actionId)
523 int orientationStatus = 0;
524 Rectangle popupLableRect;
529 if (_inErrorState == true)
531 AppLog("Already in the error state");
534 _inErrorState = true;
535 _isProcessedEvent = false;
537 AppLog("MultiForm::ShowErrorMessagePopup\n");
538 orientationStatus = GetOrientationStatus();
539 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
540 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
542 _pErrorMessagePopup = new (std::nothrow) Popup;
543 if (_pErrorMessagePopup == null)
547 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
548 _pErrorMessagePopup->SetTitleText(L"Error");
550 _pErrorMessagePopupLabel = new (std::nothrow) Label;
551 if (_pErrorMessagePopupLabel == null)
556 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
558 popupLableRect.x = 0;
559 popupLableRect.y = 0;
561 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
562 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
564 _pErrorMessagePopupBtn = new (std::nothrow) Button;
565 if (_pErrorMessagePopupBtn == null)
570 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
571 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
573 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
574 ERROR_MESSAGE_POPUP_BUTTON_W,
575 ERROR_MESSAGE_POPUP_BUTTON_H),
577 _pErrorMessagePopupBtn->SetActionId(actionId);
578 _pErrorMessagePopupBtn->AddActionEventListener(*this);
579 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
584 _pErrorMessagePopup = new (std::nothrow) Popup;
585 if (_pErrorMessagePopup == null)
589 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
590 _pErrorMessagePopup->SetTitleText(L"Error");
592 _pErrorMessagePopupLabel = new (std::nothrow) Label;
593 if (_pErrorMessagePopupLabel == null)
598 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
600 popupLableRect.x = 0;
601 popupLableRect.y = 0;
603 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
604 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
606 _pErrorMessagePopupBtn = new (std::nothrow) Button;
607 if (_pErrorMessagePopupBtn == null)
612 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W/2);
613 yPos = ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H;
615 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
617 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
618 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
619 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
621 _pErrorMessagePopupBtn->SetActionId(actionId);
622 _pErrorMessagePopupBtn->AddActionEventListener(*this);
623 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
625 _pErrorMessagePopup->SetPropagatedKeyEventListener(this);
626 _pErrorMessagePopupLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
627 _pErrorMessagePopupLabel->SetTextConfig(ERROR_MESSAGE_POPUP_LABEL_TEXT_FONT, LABEL_TEXT_STYLE_NORMAL);
628 message.Append(pMessage);
629 _pErrorMessagePopupLabel->SetText(message);
630 _pErrorMessagePopupLabel->RequestRedraw();
632 _pErrorMessagePopup->Show();
635 AppLog("MessagePopup Show failed due to OUT_OF_MEMORY");
640 MultiForm::ShowMessagePopup(String title,String message, unsigned int actionId)
642 int orientationStatus = 0;
643 Rectangle popupLableRect;
647 if (_inErrorState == true)
649 AppLog("Already in the error state");
652 _inErrorState = true;
653 _isProcessedEvent = false;
655 AppLog("MultiForm::ShowErrorMessagePopup\n");
656 orientationStatus = GetOrientationStatus();
657 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
658 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
660 _pErrorMessagePopup = new (std::nothrow) Popup;
661 if (_pErrorMessagePopup == null)
665 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
666 _pErrorMessagePopup->SetTitleText(title);
668 _pErrorMessagePopupLabel = new (std::nothrow) Label;
669 if (_pErrorMessagePopupLabel == null)
674 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
676 popupLableRect.x = 0;
677 popupLableRect.y = 0;
679 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
680 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
682 _pErrorMessagePopupBtn = new (std::nothrow) Button;
683 if (_pErrorMessagePopupBtn == null)
688 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
689 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
691 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
692 ERROR_MESSAGE_POPUP_BUTTON_W,
693 ERROR_MESSAGE_POPUP_BUTTON_H),
695 _pErrorMessagePopupBtn->SetActionId(actionId);
696 _pErrorMessagePopupBtn->AddActionEventListener(*this);
697 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
702 _pErrorMessagePopup = new (std::nothrow) Popup;
703 if (_pErrorMessagePopup == null)
707 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
708 _pErrorMessagePopup->SetTitleText(title);
710 _pErrorMessagePopupLabel = new (std::nothrow) Label;
711 if (_pErrorMessagePopupLabel == null)
716 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
718 popupLableRect.x = 0;
719 popupLableRect.y = 0;
721 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
722 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
724 _pErrorMessagePopupBtn = new (std::nothrow) Button;
725 if (_pErrorMessagePopupBtn == null)
730 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W/2);
731 yPos = ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H;
733 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
735 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
736 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
737 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
739 _pErrorMessagePopupBtn->SetActionId(actionId);
740 _pErrorMessagePopupBtn->AddActionEventListener(*this);
741 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
743 _pErrorMessagePopup->SetPropagatedKeyEventListener(this);
744 _pErrorMessagePopupLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
745 _pErrorMessagePopupLabel->SetTextConfig(ERROR_MESSAGE_POPUP_LABEL_TEXT_FONT, LABEL_TEXT_STYLE_NORMAL);
746 _pErrorMessagePopupLabel->SetText(message);
747 _pErrorMessagePopupLabel->RequestRedraw();
749 _pErrorMessagePopup->Show();
752 AppLog("MessagePopup Show failed due to OUT_OF_MEMORY");
756 MultiForm::ShowErrorMessagePopup(String title,unsigned int actionId, const char* pFormat,...)
758 int orientationStatus = 0;
759 Rectangle popupLableRect;
766 va_start(ap, pFormat);
767 vsnprintf(text, sizeof(text), pFormat, ap);
771 if (_inErrorState == true)
773 AppLog("Already in the error state");
776 _inErrorState = true;
777 _isProcessedEvent = false;
779 AppLog("MultiForm::ShowErrorMessagePopup\n");
780 orientationStatus = GetOrientationStatus();
781 if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
782 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
784 _pErrorMessagePopup = new (std::nothrow) Popup;
785 if (_pErrorMessagePopup == null)
789 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
790 _pErrorMessagePopup->SetTitleText(title);
791 _pErrorMessagePopupLabel = new (std::nothrow) Label;
792 if (_pErrorMessagePopupLabel == null)
797 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
799 popupLableRect.x = 0;
800 popupLableRect.y = 0;
802 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
803 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
805 _pErrorMessagePopupBtn = new (std::nothrow) Button;
806 if (_pErrorMessagePopupBtn == null)
811 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
812 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
814 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
815 ERROR_MESSAGE_POPUP_BUTTON_W,
816 ERROR_MESSAGE_POPUP_BUTTON_H),
818 _pErrorMessagePopupBtn->SetActionId(actionId);
819 _pErrorMessagePopupBtn->AddActionEventListener(*this);
820 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
825 _pErrorMessagePopup = new (std::nothrow) Popup;
826 if (_pErrorMessagePopup == null)
830 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
831 _pErrorMessagePopup->SetTitleText(title);
833 _pErrorMessagePopupLabel = new (std::nothrow) Label;
834 if (_pErrorMessagePopupLabel == null)
839 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
841 popupLableRect.x = 0;
842 popupLableRect.y = 0;
844 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
845 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
847 _pErrorMessagePopupBtn = new (std::nothrow) Button;
848 if (_pErrorMessagePopupBtn == null)
853 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W/2);
854 yPos = ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H;
856 yPos = (popupLableRect.height - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
858 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
859 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
860 ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
862 _pErrorMessagePopupBtn->SetActionId(actionId);
863 _pErrorMessagePopupBtn->AddActionEventListener(*this);
864 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
866 _pErrorMessagePopup->SetPropagatedKeyEventListener(this);
867 _pErrorMessagePopupLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
868 _pErrorMessagePopupLabel->SetTextConfig(ERROR_MESSAGE_POPUP_LABEL_TEXT_FONT, LABEL_TEXT_STYLE_NORMAL);
869 _pErrorMessagePopupLabel->SetText(msg);
870 _pErrorMessagePopupLabel->RequestRedraw();
872 _pErrorMessagePopup->Show();
875 AppLog("MessagePopup Show failed due to OUT_OF_MEMORY");
879 MultiForm::ClearErrorPopup(void)
881 if (_pErrorMessagePopup != null)
883 _pErrorMessagePopup->RemoveAllControls();
884 _pErrorMessagePopup->SetShowState(false);
885 AppLog(" Removing the control");
886 SAFE_DELETE(_pErrorMessagePopup);
888 _inErrorState = false;
892 MultiForm::GetErrorPopupState(void) const
894 return _inErrorState;
897 Tizen::Graphics::Rectangle
898 MultiForm::GetClientBounds(Tizen::Ui::Control& ctrl) const
900 Rectangle clientRect = GetClientAreaBounds();
906 MultiForm::FitControlBounds(Tizen::Ui::Control& src, Tizen::Ui::Control* pUpper, Tizen::Ui::Control* pLower, int topMargin, int bottomMargin, bool resize)
914 Rectangle clientRect = GetClientAreaBounds();
916 src.GetBounds(srcRect.x, srcRect.y, srcRect.width, srcRect.height);
918 AppLog("srcRect=(%d %d %d %d), client=(%d, %d, %d, %d), 0x%x, 0x%x %d %d, %d",
919 srcRect.x, srcRect.y, srcRect.width, srcRect.height,
920 clientRect.x, clientRect.y, clientRect.width, clientRect.height,
922 topMargin, bottomMargin, resize);
927 pUpper->GetBounds(upperRect.x, upperRect.y, upperRect.width, upperRect.height);
929 top = upperRect.y + upperRect.height;
933 top = clientRect.y + clientRect.height;
938 pLower->GetBounds(lowerRect.x, lowerRect.y, lowerRect.width, lowerRect.height);
940 bottom = lowerRect.y;
944 bottom = clientRect.height;
946 AppLog("upperRect=(%d %d %d %d), lowerRect=(%d, %d, %d, %d), %d %d",
947 upperRect.x, upperRect.y, upperRect.width, upperRect.height,
948 lowerRect.x, lowerRect.y, lowerRect.width, lowerRect.height, top, bottom);
952 srcRect.y = top + topMargin;
953 srcRect.height = bottom - top - topMargin - bottomMargin;
959 srcRect.y = top + topMargin;
961 else if (pLower != null)
963 srcRect.y = bottom - bottomMargin;
967 src.SetBounds(srcRect);
969 AppLog("srcRect=(%d %d %d %d)", srcRect.x, srcRect.y, srcRect.width, srcRect.height);
975 MultiForm::DrawBitmap(Tizen::Graphics::Rectangle rect, const Tizen::Graphics::Bitmap& bitmap, bool fit, bool clear)
977 result r = E_SUCCESS;
978 Tizen::Graphics::Bitmap* pNewBitmap = null;
983 Tizen::Graphics::Canvas* pCanvas = GetCanvasN();
984 TryCatch(pCanvas, r = GetLastResult(), "GetCanvasN failed:%s", GetErrorMessage(GetLastResult()));
994 xratio = (float) bitmap.GetWidth() / (float) rect.width;
995 yratio = (float) bitmap.GetHeight() / (float) rect.height;
997 ratio = xratio > yratio ? xratio : yratio;
998 if (fit && ratio > 1.0)
1000 // make resized image and display.
1001 width = (int) ((float) bitmap.GetWidth() / ratio);
1002 height = (int) ((float) bitmap.GetHeight() / ratio);
1003 Rectangle newRect(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
1004 pNewBitmap = new (std::nothrow) Bitmap();
1005 r = pNewBitmap->Construct(bitmap, newRect);
1006 TryCatch(r == E_SUCCESS, , "pNewBitmap->Construct failed:%s", GetErrorMessage(r));
1007 r = pNewBitmap->Scale(Dimension(width, height));
1008 TryCatch(r == E_SUCCESS, , "pNewBitmap->Scale:%s %d %d", GetErrorMessage(r), width, height);
1009 x = rect.x + (rect.width - pNewBitmap->GetWidth()) / 2;
1010 y = rect.y + (rect.height - pNewBitmap->GetHeight()) / 2;
1012 AppLog("Enter %x %d %d %d %d", pNewBitmap, x, y, pNewBitmap->GetWidth(), pNewBitmap->GetHeight());
1013 r = pCanvas->DrawBitmap(Tizen::Graphics::Point(x, y), *pNewBitmap);
1015 else if (ratio < 1.0)
1018 x = rect.x + (rect.width - bitmap.GetWidth()) / 2;
1019 y = rect.y + (rect.height - bitmap.GetHeight()) / 2;
1021 AppLog("Enter %d %d %x", x, y, &bitmap);
1022 r = pCanvas->DrawBitmap(Tizen::Graphics::Point(x, y), bitmap);
1027 AppLog("Enter %d %d %x", rect.x, rect.y, &bitmap);
1028 r = pCanvas->DrawBitmap(Tizen::Graphics::Point(rect.x, rect.y), bitmap);
1030 TryCatch(r == E_SUCCESS, , "pCanvas->DrawBitmap failed:%s", GetErrorMessage(r));
1034 SAFE_DELETE(pNewBitmap);
1035 SAFE_DELETE(pCanvas);
1041 MultiForm::SetHeaderText(const Tizen::Base::String& title)
1043 result r = E_SUCCESS;
1044 Header* pHeader = GetHeader();
1045 TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1047 pHeader->SetTitleText(title);
1049 _headerText = title;
1056 MultiForm::SetHeaderText(const char* format, ...)
1062 va_start(ap, format);
1063 vsnprintf(text, sizeof(text), format, ap);
1066 return SetHeaderText(title);
1072 MultiForm::SetHeaderItem(ButtonPosition position, const Tizen::Base::String& text, int actionId)
1074 result r = E_SUCCESS;
1076 Header* pHeader = GetHeader();
1077 TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1079 item.Construct(BUTTON_ITEM_STYLE_TEXT, actionId);
1081 item.SetActionId(actionId);
1082 pHeader->SetButton(position, item);
1083 pHeader->RequestRedraw();
1092 MultiForm::SetHeaderSuffix(const char* format, ...)
1094 result r = E_SUCCESS;
1100 va_start(ap, format);
1101 vsnprintf(text, sizeof(text), format, ap);
1105 Header* pHeader = GetHeader();
1106 TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1108 pHeader->SetTitleText(_headerText + suffix);
1109 pHeader->RequestRedraw();
1116 MultiForm::AddHeaderEventListener(Tizen::Ui::IActionEventListener* pListener)
1118 result r = E_SUCCESS;
1119 Header* pHeader = GetHeader();
1120 TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1122 if (pListener != null)
1124 pHeader->AddActionEventListener(*pListener);
1132 MultiForm::SetStepInfo(int stepCount, int currIndex, int prevIndex, int nextIndex)
1134 __stepCount = stepCount;
1135 __prevIndex = prevIndex;
1136 __nextIndex = nextIndex;
1137 __stepIndex = currIndex;
1138 __prevDisabled = true;
1139 if (__stepCount > 1)
1141 __nextDisabled = false;
1145 __nextDisabled = true;
1148 if (__stepCount > 0)
1150 SetHeaderSuffix("(%d/%d)", __stepIndex + 1, __stepCount);
1153 if (__stepCount > 1 && __stepIndex != 0)
1155 ShowFooterItem(__prevIndex, true);
1159 ShowFooterItem(__prevIndex, false);
1162 if (__stepCount > 1 && __stepIndex + 1 < __stepCount)
1164 ShowFooterItem(__nextIndex, true);
1168 ShowFooterItem(__nextIndex, false);
1176 MultiForm::SetStepIndex(int index)
1179 if (__stepCount > 0)
1181 SetHeaderSuffix("(%d/%d)", index + 1, __stepCount);
1184 if (__stepIndex > index) // moved prev
1186 if (__stepCount > 1 && index != 0)
1188 if (__prevDisabled == true)
1190 ShowFooterItem(__prevIndex, true);
1191 __prevDisabled = false;
1196 ShowFooterItem(__prevIndex, false);
1197 __prevDisabled = true;
1200 if (__nextDisabled == true)
1202 ShowFooterItem(__nextIndex, true);
1203 __nextDisabled = false;
1206 else // if __stepIndex < index // moved next
1208 if (__stepCount > 1 && index + 1 < __stepCount)
1210 if (__nextDisabled == true)
1212 ShowFooterItem(__nextIndex, true);
1213 __nextDisabled = false;
1218 ShowFooterItem(__nextIndex, false);
1219 __nextDisabled = true;
1222 if (__prevDisabled == true)
1224 ShowFooterItem(__prevIndex, true);
1225 __prevDisabled = false;
1229 __stepIndex = index;
1235 MultiForm::CurrStep(void)
1241 MultiForm::NextStep(void)
1243 if ((__stepIndex + 1) < __stepCount)
1245 SetStepIndex(__stepIndex + 1);
1251 MultiForm::PrevStep(void)
1253 if (__stepIndex > 0)
1255 SetStepIndex(__stepIndex - 1);
1261 MultiForm::GetTotalStep(void)
1267 MultiForm::ShowFooter(bool show)
1269 result r = E_SUCCESS;
1270 Footer* pFooter = GetFooter();
1271 TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1272 pFooter->SetShowState(show);
1280 MultiForm::ShowFooterItem(int index, bool show)
1282 result r = E_SUCCESS;
1283 Footer* pFooter = GetFooter();
1284 TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1286 pFooter->SetItemEnabled(index, show);
1287 pFooter->Invalidate(true);
1293 MultiForm::SetFooterStyle(FooterStyle style, int actionId, Tizen::Ui::IActionEventListener* pListener)
1295 result r = E_SUCCESS;
1296 Footer* pFooter = GetFooter();
1297 TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1299 pFooter->SetStyle(style);
1302 pFooter->AddActionEventListener(*pListener);
1310 MultiForm::AddFooterItem(const Tizen::Base::String& text, int actionId)
1312 result r = E_SUCCESS;
1314 Footer* pFooter = GetFooter();
1315 TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1317 item.Construct(actionId);
1319 pFooter->AddItem(item);
1326 MultiForm::SetFooterItem(int index, const Tizen::Base::String& text, int actionId)
1328 result r = E_SUCCESS;
1330 Footer* pFooter = GetFooter();
1331 TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1333 item.Construct(actionId);
1336 pFooter->SetItemAt(index, item);
1344 MultiForm::RemoveFooterItem(int index)
1346 result r = E_SUCCESS;
1348 Footer* pFooter = GetFooter();
1349 TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1351 pFooter->RemoveItemAt(index);
1359 MultiForm::SetControlText(Label* pLabel, const char* format, ...)
1364 result r = E_SUCCESS;
1366 TryCatch(pLabel, r = E_INVALID_ARG, "pLabel is null");
1367 va_start(ap, format);
1368 vsnprintf(text, sizeof(text), format, ap);
1371 pLabel->SetText(str);
1379 MultiForm::SetControlText(Button* pButton, const char* format, ...)
1384 result r = E_SUCCESS;
1386 TryCatch(pButton, r = E_INVALID_ARG, "pButton is null");
1387 va_start(ap, format);
1388 vsnprintf(text, sizeof(text), format, ap);
1391 pButton->SetText(str);
1399 MultiForm::SetControlText(EditArea* pEditArea, const char* format, ...)
1404 result r = E_SUCCESS;
1406 TryCatch(pEditArea, r = E_INVALID_ARG, "pEditArea is null");
1407 va_start(ap, format);
1408 vsnprintf(text, sizeof(text), format, ap);
1411 pEditArea->SetText(str);
1412 pEditArea->SetCursorPosition(0);
1420 MultiForm::SetControlText(EditArea* pEditArea, const Tizen::Base::String& str)
1422 result r = E_SUCCESS;
1424 TryCatch(pEditArea, r = E_INVALID_ARG, "pEditArea is null");
1425 pEditArea->SetText(str);
1426 pEditArea->SetCursorPosition(0);
1434 MultiForm::AppendControlText(EditArea* pEditArea, const char* format, ...)
1439 result r = E_SUCCESS;
1441 TryCatch(pEditArea, r = E_INVALID_ARG, "pEditArea is null");
1442 va_start(ap, format);
1443 vsnprintf(text, sizeof(text), format, ap);
1446 pEditArea->AppendText(str);
1447 pEditArea->SetCursorPosition(0);
1455 MultiForm::HideAndGetBounds(Tizen::Ui::Control* pCtrl, Tizen::Graphics::Rectangle& rect)
1457 result r = E_SUCCESS;
1458 TryCatch(pCtrl, r = E_SYSTEM, "pCtrl is null");
1459 pCtrl->SetShowState(false);
1462 rect = pCtrl->GetBounds();
1469 MultiForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
1471 AppLog("MultiForm::OnFormBackRequested called");
1475 MultiForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
1477 AppLog("MultiForm::OnOrientationChanged called %d", orientationStatus);