8494a932f3fd71e9afc3aed7da152442566c4b22
[apps/native/sample/MediaApp.git] / project / src / MultiForm.cpp
1 //
2 // Tizen Native SDK
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.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
19 #include <FApp.h>
20 #include <FUi.h>
21 #include <stdio.h>
22 #include <stdarg.h>
23
24 #include "MultiForm.h"
25 #include "AppConfig.h"
26 #include "MainForm.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"
33
34 #include "Audio/AudioInOut.h"
35 #include "Audio/TonePlayerForm.h"
36 #include "Audio/AudioEqualizerForm.h"
37 #include "Audio/GlesCubePlayer.h"
38
39 #include "Recorder/AudioRecorderForm.h"
40 #include "Recorder/VideoRecorderForm.h"
41
42 #include "Camera/CameraCaptureForm.h"
43
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"
49
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"
55
56 #include "MediaPlayerForm.h"
57
58 using namespace Tizen::Ui;
59 using namespace Tizen::Ui::Controls;
60 using namespace Tizen::Ui::Scenes;
61
62 static const int ERROR_MESSAGE_POPUP_WIDTH = 470;
63 static const int ERROR_MESSAGE_POPUP_HEIGHT = 480;
64
65 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH = 470;
66 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT = 400;
67
68 static const int ERROR_MESSAGE_POPUP_BUTTON_W = 100;
69 static const int ERROR_MESSAGE_POPUP_BUTTON_H = 60;
70
71 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W = 100;
72 static const int ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H = 60;
73
74 static const int ERROR_MESSAGE_POPUP_LABEL_TEXT_FONT = 30;
75
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;
81
82
83 HashMap* MultiForm::_pSceneProcMap = null;
84
85 extern void* pMainMediaAppFrame;
86
87 MultiForm::MultiForm(void)
88         : _pFrame( (Tizen::Ui::Controls::Frame*) pMainMediaAppFrame),
89           _inErrorState(false),
90           _isProcessedEvent(false),
91           _pErrorMessagePopup(null),
92           __stepCount(0),
93           __stepIndex(0),
94           __prevIndex(0),
95           __nextIndex(0)
96
97 {
98 }
99
100 MultiForm::~MultiForm(void)
101 {
102 }
103
104 result
105 MultiForm::Construct(Tizen::Base::String resourceId)
106 {
107         result r = E_SUCCESS;
108
109         _pConfig = AppConfig::GetInstance();
110
111         r = Form::Construct(resourceId);
112         TryCatch(r == E_SUCCESS, , "Form::Construct %s", GetErrorMessage(r));
113
114         SetFormBackEventListener(this);
115         AddOrientationEventListener(*this);
116
117 CATCH:
118         return r;
119 }
120
121 result
122 MultiForm::OnInitializing(void)
123 {
124         return E_SUCCESS;
125 }
126
127
128 result
129 MultiForm::Activate(void* pParam)
130 {
131         return E_SUCCESS;
132 }
133
134 MultiFormCreateProc
135 MultiForm::GetFormProc(Tizen::Base::String formId)
136 {
137         result r = E_SUCCESS;
138         bool out;
139
140         if (_pSceneProcMap == null)
141         {
142                 return null;
143         }
144
145         r = _pSceneProcMap->ContainsKey(formId, out);
146
147         if (!IsFailed(r) || out == true)
148         {
149
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();
155                 if (proc)
156                 {
157                         return  proc;
158                 }
159                 else
160                 {
161                         return null;
162                 }
163         }
164
165
166 CATCH:
167         return null;
168 }
169
170 result
171 MultiForm::RegisterAllScenes()
172 {
173         result r = E_SUCCESS;
174
175         r = MultiForm::SceneRegister(MainForm::GetFormId(), MainForm::GetSceneId(), MainForm::FormCreateFunc);
176         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
177
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));
181
182         r = MultiForm::SceneRegister(TonePlayerForm::GetFormId(), TonePlayerForm::GetSceneId(), TonePlayerForm::FormCreateFunc);
183         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
184
185         r = MultiForm::SceneRegister(AudioEqualizerForm::GetFormId(), AudioEqualizerForm::GetSceneId(), AudioEqualizerForm::FormCreateFunc);\r
186         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
187
188         r = MultiForm::SceneRegister(GlesCubePlayerForm::GetFormId(), GlesCubePlayerForm::GetSceneId(), GlesCubePlayerForm::FormCreateFunc);
189         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
190
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));
194
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));
198
199         r = MultiForm::SceneRegister(AudioEncoderForm::GetFormId(), AudioEncoderForm::GetSceneId(), AudioEncoderForm::FormCreateFunc);
200         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
201
202         r = MultiForm::SceneRegister(VideoDecoderForm::GetFormId(), VideoDecoderForm::GetSceneId(), VideoDecoderForm::FormCreateFunc);
203         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
204
205         r = MultiForm::SceneRegister(VideoEncoderForm::GetFormId(), VideoEncoderForm::GetSceneId(), VideoEncoderForm::FormCreateFunc);
206         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
207
208         r = MultiForm::SceneRegister(VideoFrameExtractorForm::GetFormId(), VideoFrameExtractorForm::GetSceneId(), VideoFrameExtractorForm::FormCreateFunc);
209         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
210
211
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));
215
216         r = MultiForm::SceneRegister(ImageColorConvertForm::GetFormId(), ImageColorConvertForm::GetSceneId(), ImageColorConvertForm::FormCreateFunc);
217         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
218
219         r = MultiForm::SceneRegister(ImageConverterForm::GetFormId(), ImageConverterForm::GetSceneId(), ImageConverterForm::FormCreateFunc);
220         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
221
222         r = MultiForm::SceneRegister(ImageFlipRotateForm::GetFormId(), ImageFlipRotateForm::GetSceneId(), ImageFlipRotateForm::FormCreateFunc);
223         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
224
225         r = MultiForm::SceneRegister(ImageResizeForm::GetFormId(), ImageResizeForm::GetSceneId(), ImageResizeForm::FormCreateFunc);
226         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
227
228         r = MultiForm::SceneRegister(ImageViewerForm::GetFormId(), ImageViewerForm::GetSceneId(), ImageViewerForm::FormCreateFunc);
229         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
230
231
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));
235
236         r = MultiForm::SceneRegister(CaptureVideoForm::GetFormId(), CaptureVideoForm::GetSceneId(), CaptureVideoForm::FormCreateFunc);
237         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
238
239         r = MultiForm::SceneRegister(MultiPlayForm::GetFormId(), MultiPlayForm::GetSceneId(), MultiPlayForm::FormCreateFunc);
240         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
241
242         r = MultiForm::SceneRegister(PlayerForm::GetFormId(), PlayerForm::GetSceneId(), PlayerForm::FormCreateFunc);
243         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
244
245         r = MultiForm::SceneRegister(VideoRecorderPlayerForm::GetFormId(), VideoRecorderPlayerForm::GetSceneId(), VideoRecorderPlayerForm::FormCreateFunc);
246         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
247
248
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));
252
253         r = MultiForm::SceneRegister(VideoRecorderForm::GetFormId(), VideoRecorderForm::GetSceneId(), VideoRecorderForm::FormCreateFunc);
254         TryReturn(r == E_SUCCESS, r, "Error In scene Registration:%s", GetErrorMessage(r));
255
256
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));
260
261         return r;
262 }
263 result
264 MultiForm::SceneRegister(const Tizen::Base::String& formId, const Tizen::Ui::Scenes::SceneId& sceneId, MultiFormCreateProc proc)
265 {
266         bool out;
267         result r = E_SUCCESS;
268         SceneManager* pSceneManager = SceneManager::GetInstance();
269
270         if (_pSceneProcMap == null)
271         {
272                 _pSceneProcMap = new (std::nothrow) HashMap();
273                 _pSceneProcMap->Construct();
274         }
275         r = _pSceneProcMap->ContainsKey(formId, out);
276         TryCatch(r == E_SUCCESS, , "_pSceneProcMap.ContainsKey failed : %s", GetErrorMessage(r));
277         if (out == true)
278         {
279                 r = _pSceneProcMap->SetValue(*(new String(formId)), *(new Integer((int) (proc))));
280         }
281         else
282         {
283                 r = _pSceneProcMap->Add(*(new String(formId)), *(new Integer((int) (proc))));
284         }
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"");
287
288 CATCH:
289         return r;
290 }
291
292
293 void
294 MultiForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
295 {
296 }
297
298 void
299 MultiForm::OnClientDeactivated(MultiForm* pForm, void* pParam)
300 {
301 }
302
303 void
304 MultiForm::Deactivate(void)
305 {
306         OnDeactivate();
307 }
308
309 void
310 MultiForm::OnDeactivate(void)
311 {
312         SceneManager* pSceneManager = SceneManager::GetInstance();
313         pSceneManager->GoBackward(BackwardSceneTransition());
314 }
315
316 void
317 MultiForm::OnForeground(void)
318 {
319 }
320
321 void
322 MultiForm::OnBackground(void)
323 {
324 }
325
326 void
327 MultiForm::OnLowMemory(void)
328 {
329 }
330
331 void
332 MultiForm::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
333 {
334 }
335
336 void
337 MultiForm::OnScreenOn(void)
338 {
339 }
340
341 void
342 MultiForm::OnScreenOff(void)
343 {
344 }
345
346 void
347 MultiForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
348 {
349
350 }
351
352 bool
353 MultiForm::OnKeyPressed(Tizen::Ui::Control& source, const Tizen::Ui::KeyEventInfo& keyEventInfo)
354 {
355         AppLog("Here - %d", keyEventInfo.GetKeyCode());
356         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
357         {
358                 if (_pErrorMessagePopup != null)
359                 {
360                         _pErrorMessagePopup->RemoveAllControls();
361                         _pErrorMessagePopup->SetShowState(false);
362                         AppLog(" Removing the control");
363                         SAFE_DELETE(_pErrorMessagePopup);
364                         _isProcessedEvent = true;
365                         _inErrorState = false;
366                 }
367                 return true;
368         }
369         return false;
370 }
371
372 void
373 MultiForm::ShowErrorMessagePopup(String filePath, String Class, const char* pMethod, result r, const char* pSrcfileName, int lineNo, String errorMsg)
374 {
375         String errorMessage;
376         int orientationStatus = 0;
377         Rectangle popupLableRect;
378         int xPos = 0;
379         int yPos = 0;
380
381         if (_inErrorState == true)
382         {
383                 AppLog("Already in the error state");
384                 return;
385         }
386         _inErrorState = true;
387         _isProcessedEvent = false;
388
389         AppLog("MultiForm::ShowErrorMessagePopup\n");
390         orientationStatus = GetOrientationStatus();
391         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
392                 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
393         {
394                 _pErrorMessagePopup = new (std::nothrow) Popup;
395                 if (_pErrorMessagePopup == null)
396                 {
397                         goto FAIL;
398                 }
399                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
400                 _pErrorMessagePopup->SetTitleText(L"Error");
401
402                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
403                 if (_pErrorMessagePopupLabel == null)
404                 {
405                         goto FAIL;
406                 }
407
408                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
409
410                 popupLableRect.x = 0;
411                 popupLableRect.y = 0;
412
413                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
414                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
415
416                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
417                 if (_pErrorMessagePopupBtn == null)
418                 {
419                         goto FAIL;
420                 }
421
422                 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
423                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
424
425                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
426                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_W,
427                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_H),
428                                                                                  L"Ok");
429                 _pErrorMessagePopupBtn->SetActionId(ID_BUTTON_ERROR_POPUP_OK);
430                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
431                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
432
433         }
434         else
435         {
436                 _pErrorMessagePopup = new (std::nothrow) Popup;
437                 if (_pErrorMessagePopup == null)
438                 {
439                         goto FAIL;
440                 }
441                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
442                 _pErrorMessagePopup->SetTitleText(L"Error");
443
444                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
445                 if (_pErrorMessagePopupLabel == null)
446                 {
447                         goto FAIL;
448                 }
449
450                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
451
452                 popupLableRect.x = 0;
453                 popupLableRect.y = 0;
454
455                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
456                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
457
458                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
459                 if (_pErrorMessagePopupBtn == null)
460                 {
461                         goto FAIL;
462                 }
463
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;
466
467                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
468
469                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
470                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
471                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
472                                                                                  L"Ok");
473                 _pErrorMessagePopupBtn->SetActionId(ID_BUTTON_ERROR_POPUP_OK);
474                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
475                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
476         }
477
478         _pErrorMessagePopup->SetShowState(true);
479
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)
491         {
492                 errorMessage.Append(errorMsg);
493         }
494         else
495         {
496                 errorMessage.Append(GetErrorMessage(r));
497         }
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');
505
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();
511
512         r = _pErrorMessagePopup->Show();
513         AppLog("_pErrorMessagePopup Show: %s\n", GetErrorMessage(r));
514
515         return;
516 FAIL:
517         AppLog("_pErrorMessagePopup Show failed due to OUT_OF_MEMORY");
518 }
519
520 void
521 MultiForm::ShowMessagePopup(const char* pMessage, unsigned int actionId)
522 {
523         int orientationStatus = 0;
524         Rectangle popupLableRect;
525         String message;
526         int xPos = 0;
527         int yPos = 0;
528
529         if (_inErrorState == true)
530         {
531                 AppLog("Already in the error state");
532                 return;
533         }
534         _inErrorState = true;
535         _isProcessedEvent = false;
536
537         AppLog("MultiForm::ShowErrorMessagePopup\n");
538         orientationStatus = GetOrientationStatus();
539         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
540                 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
541         {
542                 _pErrorMessagePopup = new (std::nothrow) Popup;
543                 if (_pErrorMessagePopup == null)
544                 {
545                         goto FAIL;
546                 }
547                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
548                 _pErrorMessagePopup->SetTitleText(L"Error");
549
550                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
551                 if (_pErrorMessagePopupLabel == null)
552                 {
553                         goto FAIL;
554                 }
555
556                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
557
558                 popupLableRect.x = 0;
559                 popupLableRect.y = 0;
560
561                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
562                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
563
564                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
565                 if (_pErrorMessagePopupBtn == null)
566                 {
567                         goto FAIL;
568                 }
569
570                 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
571                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
572
573                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
574                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_W,
575                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_H),
576                                                                                  L"Ok");
577                 _pErrorMessagePopupBtn->SetActionId(actionId);
578                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
579                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
580
581         }
582         else
583         {
584                 _pErrorMessagePopup = new (std::nothrow) Popup;
585                 if (_pErrorMessagePopup == null)
586                 {
587                         goto FAIL;
588                 }
589                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
590                 _pErrorMessagePopup->SetTitleText(L"Error");
591
592                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
593                 if (_pErrorMessagePopupLabel == null)
594                 {
595                         goto FAIL;
596                 }
597
598                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
599
600                 popupLableRect.x = 0;
601                 popupLableRect.y = 0;
602
603                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
604                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
605
606                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
607                 if (_pErrorMessagePopupBtn == null)
608                 {
609                         goto FAIL;
610                 }
611
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;
614
615                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
616
617                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
618                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
619                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
620                                                                                  L"Ok");
621                 _pErrorMessagePopupBtn->SetActionId(actionId);
622                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
623                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
624         }
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();
631
632         _pErrorMessagePopup->Show();
633         return;
634         FAIL:
635         AppLog("MessagePopup Show failed due to OUT_OF_MEMORY");
636 }
637
638
639 void
640 MultiForm::ShowMessagePopup(String title,String message, unsigned int actionId)
641 {
642         int orientationStatus = 0;
643         Rectangle popupLableRect;
644         int xPos = 0;
645         int yPos = 0;
646
647         if (_inErrorState == true)
648         {
649                 AppLog("Already in the error state");
650                 return;
651         }
652         _inErrorState = true;
653         _isProcessedEvent = false;
654
655         AppLog("MultiForm::ShowErrorMessagePopup\n");
656         orientationStatus = GetOrientationStatus();
657         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
658                 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
659         {
660                 _pErrorMessagePopup = new (std::nothrow) Popup;
661                 if (_pErrorMessagePopup == null)
662                 {
663                         goto FAIL;
664                 }
665                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_WIDTH, ERROR_MESSAGE_POPUP_HEIGHT));
666                 _pErrorMessagePopup->SetTitleText(title);
667
668                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
669                 if (_pErrorMessagePopupLabel == null)
670                 {
671                         goto FAIL;
672                 }
673
674                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
675
676                 popupLableRect.x = 0;
677                 popupLableRect.y = 0;
678
679                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
680                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
681
682                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
683                 if (_pErrorMessagePopupBtn == null)
684                 {
685                         goto FAIL;
686                 }
687
688                 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
689                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
690
691                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
692                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_W,
693                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_H),
694                                                                                  L"Ok");
695                 _pErrorMessagePopupBtn->SetActionId(actionId);
696                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
697                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
698
699         }
700         else
701         {
702                 _pErrorMessagePopup = new (std::nothrow) Popup;
703                 if (_pErrorMessagePopup == null)
704                 {
705                         goto FAIL;
706                 }
707                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
708                 _pErrorMessagePopup->SetTitleText(title);
709
710                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
711                 if (_pErrorMessagePopupLabel == null)
712                 {
713                         goto FAIL;
714                 }
715
716                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
717
718                 popupLableRect.x = 0;
719                 popupLableRect.y = 0;
720
721                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
722                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
723
724                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
725                 if (_pErrorMessagePopupBtn == null)
726                 {
727                         goto FAIL;
728                 }
729
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;
732
733                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
734
735                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
736                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
737                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
738                                                                                  L"Ok");
739                 _pErrorMessagePopupBtn->SetActionId(actionId);
740                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
741                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
742         }
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();
748
749         _pErrorMessagePopup->Show();
750         return;
751         FAIL:
752         AppLog("MessagePopup Show failed due to OUT_OF_MEMORY");
753 }
754
755 void
756 MultiForm::ShowErrorMessagePopup(String title,unsigned int actionId, const char* pFormat,...)
757 {
758         int orientationStatus = 0;
759         Rectangle popupLableRect;
760         int xPos = 0;
761         int yPos = 0;
762         va_list ap;
763         char text[1024];
764         String msg;
765
766         va_start(ap, pFormat);
767         vsnprintf(text, sizeof(text), pFormat, ap);
768         va_end(ap);
769         msg = text;
770
771         if (_inErrorState == true)
772         {
773                 AppLog("Already in the error state");
774                 return;
775         }
776         _inErrorState = true;
777         _isProcessedEvent = false;
778
779         AppLog("MultiForm::ShowErrorMessagePopup\n");
780         orientationStatus = GetOrientationStatus();
781         if (orientationStatus == ORIENTATION_STATUS_PORTRAIT ||
782                 orientationStatus == ORIENTATION_STATUS_PORTRAIT_REVERSE)
783         {
784                 _pErrorMessagePopup = new (std::nothrow) Popup;
785                 if (_pErrorMessagePopup == null)
786                 {
787                         goto FAIL;
788                 }
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)
793                 {
794                         goto FAIL;
795                 }
796
797                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
798
799                 popupLableRect.x = 0;
800                 popupLableRect.y = 0;
801
802                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
803                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
804
805                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
806                 if (_pErrorMessagePopupBtn == null)
807                 {
808                         goto FAIL;
809                 }
810
811                 xPos = (popupLableRect.width/2)-(ERROR_MESSAGE_POPUP_BUTTON_W/2);
812                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_BUTTON_H - 20);
813
814                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
815                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_W,
816                                                                                                    ERROR_MESSAGE_POPUP_BUTTON_H),
817                                                                                  L"Ok");
818                 _pErrorMessagePopupBtn->SetActionId(actionId);
819                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
820                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
821
822         }
823         else
824         {
825                 _pErrorMessagePopup = new (std::nothrow) Popup;
826                 if (_pErrorMessagePopup == null)
827                 {
828                         goto FAIL;
829                 }
830                 _pErrorMessagePopup->Construct(true, Dimension(ERROR_MESSAGE_POPUP_LANDSCAPE_WIDTH, ERROR_MESSAGE_POPUP_LANDSCAPE_HEIGHT));
831                 _pErrorMessagePopup->SetTitleText(title);
832
833                 _pErrorMessagePopupLabel = new (std::nothrow) Label;
834                 if (_pErrorMessagePopupLabel == null)
835                 {
836                         goto FAIL;
837                 }
838
839                 popupLableRect = _pErrorMessagePopup->GetClientAreaBounds();
840
841                 popupLableRect.x = 0;
842                 popupLableRect.y = 0;
843
844                 _pErrorMessagePopupLabel->Construct(popupLableRect, L"");
845                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupLabel);
846
847                 _pErrorMessagePopupBtn = new (std::nothrow) Button;
848                 if (_pErrorMessagePopupBtn == null)
849                 {
850                         goto FAIL;
851                 }
852
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;
855
856                 yPos = (popupLableRect.height  - ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H -20);
857
858                 _pErrorMessagePopupBtn->Construct(Rectangle(xPos, yPos,
859                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_W,
860                                                                                                    ERROR_MESSAGE_POPUP_LANDSCAPE_BUTTON_H),
861                                                                                  L"Ok");
862                 _pErrorMessagePopupBtn->SetActionId(actionId);
863                 _pErrorMessagePopupBtn->AddActionEventListener(*this);
864                 _pErrorMessagePopup->AddControl(_pErrorMessagePopupBtn);
865         }
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();
871
872         _pErrorMessagePopup->Show();
873         return;
874 FAIL:
875         AppLog("MessagePopup Show failed due to OUT_OF_MEMORY");
876 }
877
878 void
879 MultiForm::ClearErrorPopup(void)
880 {
881         if (_pErrorMessagePopup != null)
882         {
883                 _pErrorMessagePopup->RemoveAllControls();
884                 _pErrorMessagePopup->SetShowState(false);
885                 AppLog(" Removing the control");
886                 SAFE_DELETE(_pErrorMessagePopup);
887         }
888         _inErrorState = false;
889 }
890
891 bool
892 MultiForm::GetErrorPopupState(void) const
893 {
894         return _inErrorState;
895 }
896
897 Tizen::Graphics::Rectangle
898 MultiForm::GetClientBounds(Tizen::Ui::Control& ctrl) const
899 {
900         Rectangle clientRect = GetClientAreaBounds();
901
902         return clientRect;
903 }
904
905 void
906 MultiForm::FitControlBounds(Tizen::Ui::Control& src, Tizen::Ui::Control* pUpper, Tizen::Ui::Control* pLower, int topMargin, int bottomMargin, bool resize)
907 {
908         int top;
909         int bottom;
910         Rectangle srcRect;
911         Rectangle upperRect;
912         Rectangle lowerRect;
913
914         Rectangle clientRect = GetClientAreaBounds();
915
916         src.GetBounds(srcRect.x, srcRect.y, srcRect.width, srcRect.height);
917
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,
921                    pUpper, pLower,
922                    topMargin, bottomMargin, resize);
923
924         if (pUpper != null)
925         {
926                 AppLog("Enter");
927                 pUpper->GetBounds(upperRect.x, upperRect.y, upperRect.width, upperRect.height);
928                 AppLog("Enter");
929                 top = upperRect.y + upperRect.height;
930         }
931         else
932         {
933                 top = clientRect.y + clientRect.height;
934         }
935         if (pLower != null)
936         {
937                 AppLog("Enter");
938                 pLower->GetBounds(lowerRect.x, lowerRect.y, lowerRect.width, lowerRect.height);
939                 AppLog("Enter");
940                 bottom = lowerRect.y;
941         }
942         else
943         {
944                 bottom = clientRect.height;
945         }
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);
949
950         if (resize == true)
951         {
952                 srcRect.y = top + topMargin;
953                 srcRect.height = bottom - top - topMargin - bottomMargin;
954         }
955         else
956         {
957                 if (pUpper != null)
958                 {
959                         srcRect.y = top + topMargin;
960                 }
961                 else if (pLower != null)
962                 {
963                         srcRect.y = bottom - bottomMargin;
964                 }
965         }
966
967         src.SetBounds(srcRect);
968
969         AppLog("srcRect=(%d %d %d %d)", srcRect.x, srcRect.y, srcRect.width, srcRect.height);
970
971 }
972
973
974 result
975 MultiForm::DrawBitmap(Tizen::Graphics::Rectangle rect, const Tizen::Graphics::Bitmap& bitmap, bool fit, bool clear)
976 {
977         result r = E_SUCCESS;
978         Tizen::Graphics::Bitmap* pNewBitmap = null;
979         int x;
980         int y;
981         int width;
982         int height;
983         Tizen::Graphics::Canvas* pCanvas = GetCanvasN();
984         TryCatch(pCanvas, r = GetLastResult(), "GetCanvasN failed:%s", GetErrorMessage(GetLastResult()));
985
986         if (clear == true)
987         {
988                 pCanvas->Clear();
989         }
990         float xratio;
991         float yratio;
992         float ratio;
993
994         xratio = (float) bitmap.GetWidth() / (float) rect.width;
995         yratio = (float) bitmap.GetHeight() / (float) rect.height;
996
997         ratio = xratio > yratio ? xratio : yratio;
998         if (fit && ratio > 1.0)
999         {
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;
1011
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);
1014         }
1015         else if (ratio < 1.0)
1016         {
1017                 // center align
1018                 x = rect.x + (rect.width - bitmap.GetWidth()) / 2;
1019                 y = rect.y + (rect.height - bitmap.GetHeight()) / 2;
1020
1021                 AppLog("Enter %d %d %x", x, y, &bitmap);
1022                 r = pCanvas->DrawBitmap(Tizen::Graphics::Point(x, y), bitmap);
1023         }
1024         else
1025         {
1026                 // top-left align
1027                 AppLog("Enter %d %d %x", rect.x, rect.y, &bitmap);
1028                 r = pCanvas->DrawBitmap(Tizen::Graphics::Point(rect.x, rect.y), bitmap);
1029         }
1030         TryCatch(r == E_SUCCESS, , "pCanvas->DrawBitmap failed:%s", GetErrorMessage(r));
1031         pCanvas->Show();
1032
1033 CATCH:
1034         SAFE_DELETE(pNewBitmap);
1035         SAFE_DELETE(pCanvas);
1036         return r;
1037 }
1038
1039
1040 result
1041 MultiForm::SetHeaderText(const Tizen::Base::String& title)
1042 {
1043         result r = E_SUCCESS;
1044         Header* pHeader = GetHeader();
1045         TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1046
1047         pHeader->SetTitleText(title);
1048         pHeader->Draw();
1049         _headerText = title;
1050
1051 CATCH:
1052         return r;
1053 }
1054
1055 result
1056 MultiForm::SetHeaderText(const char* format, ...)
1057 {
1058         va_list ap;
1059         char text[64];
1060         String title;
1061
1062         va_start(ap, format);
1063         vsnprintf(text, sizeof(text), format, ap);
1064         va_end(ap);
1065         title = text;
1066         return SetHeaderText(title);
1067 }
1068
1069
1070
1071 result
1072 MultiForm::SetHeaderItem(ButtonPosition position, const Tizen::Base::String& text, int actionId)
1073 {
1074         result r = E_SUCCESS;
1075         ButtonItem item;
1076         Header* pHeader = GetHeader();
1077         TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1078
1079         item.Construct(BUTTON_ITEM_STYLE_TEXT, actionId);
1080         item.SetText(text);
1081         item.SetActionId(actionId);
1082         pHeader->SetButton(position, item);
1083         pHeader->RequestRedraw();
1084
1085 CATCH:
1086         return r;
1087
1088 }
1089
1090
1091 result
1092 MultiForm::SetHeaderSuffix(const char* format, ...)
1093 {
1094         result r = E_SUCCESS;
1095
1096         va_list ap;
1097         char text[64];
1098         String suffix;
1099
1100         va_start(ap, format);
1101         vsnprintf(text, sizeof(text), format, ap);
1102         va_end(ap);
1103         suffix = text;
1104
1105         Header* pHeader = GetHeader();
1106         TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1107
1108         pHeader->SetTitleText(_headerText + suffix);
1109         pHeader->RequestRedraw();
1110
1111 CATCH:
1112         return r;
1113 }
1114
1115 result
1116 MultiForm::AddHeaderEventListener(Tizen::Ui::IActionEventListener* pListener)
1117 {
1118         result r = E_SUCCESS;
1119         Header* pHeader = GetHeader();
1120         TryCatch(pHeader, r = E_SYSTEM, "GetHeader failed:%s", GetErrorMessage(GetLastResult()));
1121
1122         if (pListener != null)
1123         {
1124                 pHeader->AddActionEventListener(*pListener);
1125         }
1126
1127 CATCH:
1128         return r;
1129 }
1130
1131 result
1132 MultiForm::SetStepInfo(int stepCount, int currIndex, int prevIndex, int nextIndex)
1133 {
1134         __stepCount = stepCount;
1135         __prevIndex = prevIndex;
1136         __nextIndex = nextIndex;
1137         __stepIndex = currIndex;
1138
1139         if (__stepCount > 0)
1140         {
1141                 SetHeaderSuffix("(%d/%d)", __stepIndex + 1, __stepCount);
1142         }
1143
1144         if (__stepCount > 1 && __stepIndex != 0)
1145         {
1146                 ShowFooterItem(__prevIndex, true);
1147         }
1148         else
1149         {
1150                 ShowFooterItem(__prevIndex, false);
1151         }
1152
1153         if (__stepCount > 1 && __stepIndex + 1 < __stepCount)
1154         {
1155                 ShowFooterItem(__nextIndex, true);
1156         }
1157         else
1158         {
1159                 ShowFooterItem(__nextIndex, false);
1160         }
1161
1162         return E_SUCCESS;
1163 }
1164
1165
1166 result
1167 MultiForm::SetStepIndex(int index)
1168 {
1169         __stepIndex = index;
1170
1171         if (__stepCount > 0)
1172         {
1173                 SetHeaderSuffix("(%d/%d)", __stepIndex + 1, __stepCount);
1174         }
1175
1176         if (__stepCount > 1 && __stepIndex != 0)
1177         {
1178                 ShowFooterItem(__prevIndex, true);
1179         }
1180         else
1181         {
1182                 ShowFooterItem(__prevIndex, false);
1183         }
1184
1185         if (__stepCount > 1 && __stepIndex + 1 < __stepCount)
1186         {
1187                 ShowFooterItem(__nextIndex, true);
1188         }
1189         else
1190         {
1191                 ShowFooterItem(__nextIndex, false);
1192         }
1193
1194         return E_SUCCESS;
1195 }
1196
1197 int
1198 MultiForm::CurrStep(void)
1199 {
1200         return __stepIndex;
1201 }
1202
1203 int
1204 MultiForm::NextStep(void)
1205 {
1206         if ((__stepIndex + 1) < __stepCount)
1207         {
1208                 SetStepIndex(__stepIndex + 1);
1209         }
1210         return __stepIndex;
1211 }
1212
1213 int
1214 MultiForm::PrevStep(void)
1215 {
1216         if (__stepIndex > 0)
1217         {
1218                 SetStepIndex(__stepIndex - 1);
1219         }
1220         return __stepIndex;
1221 }
1222
1223 int
1224 MultiForm::GetTotalStep(void)
1225 {
1226         return __stepCount;
1227 }
1228
1229 result
1230 MultiForm::ShowFooter(bool show)
1231 {
1232         result r = E_SUCCESS;
1233         Footer* pFooter = GetFooter();
1234         TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1235         pFooter->SetShowState(show);
1236         pFooter->Draw();
1237
1238 CATCH:
1239         return r;
1240 }
1241
1242 result
1243 MultiForm::ShowFooterItem(int index, bool show)
1244 {
1245         result r = E_SUCCESS;
1246         Footer* pFooter = GetFooter();
1247         TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1248
1249         pFooter->SetItemEnabled(index, show);
1250         pFooter->Invalidate(true);
1251 CATCH:
1252         return r;
1253 }
1254
1255 result
1256 MultiForm::SetFooterStyle(FooterStyle style, int actionId, Tizen::Ui::IActionEventListener* pListener)
1257 {
1258         result r = E_SUCCESS;
1259         Footer* pFooter = GetFooter();
1260         TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1261
1262         pFooter->SetStyle(style);
1263         if (pListener)
1264         {
1265                 pFooter->AddActionEventListener(*pListener);
1266         }
1267
1268 CATCH:
1269         return r;
1270 }
1271
1272 result
1273 MultiForm::AddFooterItem(const Tizen::Base::String& text, int actionId)
1274 {
1275         result r = E_SUCCESS;
1276         FooterItem item;
1277         Footer* pFooter = GetFooter();
1278         TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1279
1280         item.Construct(actionId);
1281         item.SetText(text);
1282         pFooter->AddItem(item);
1283
1284 CATCH:
1285         return r;
1286 }
1287
1288 result
1289 MultiForm::SetFooterItem(int index, const Tizen::Base::String& text, int actionId)
1290 {
1291         result r = E_SUCCESS;
1292         FooterItem item;
1293         Footer* pFooter = GetFooter();
1294         TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1295
1296         item.Construct(actionId);
1297         item.SetText(text);
1298
1299         pFooter->SetItemAt(index, item);
1300         pFooter->Draw();
1301
1302 CATCH:
1303         return r;
1304 }
1305
1306 result
1307 MultiForm::RemoveFooterItem(int index)
1308 {
1309         result r = E_SUCCESS;
1310         FooterItem item;
1311         Footer* pFooter = GetFooter();
1312         TryCatch(pFooter, r = E_SYSTEM, "GetFooter() failed:%s", GetErrorMessage(GetLastResult()));
1313
1314         pFooter->RemoveItemAt(index);
1315         pFooter->Draw();
1316
1317 CATCH:
1318         return r;
1319 }
1320
1321 result
1322 MultiForm::SetControlText(Label* pLabel, const char* format, ...)
1323 {
1324         va_list ap;
1325         char text[64];
1326         String str;
1327         result r = E_SUCCESS;
1328
1329         TryCatch(pLabel, r = E_INVALID_ARG, "pLabel is null");
1330         va_start(ap, format);
1331         vsnprintf(text, sizeof(text), format, ap);
1332         va_end(ap);
1333         str = text;
1334         pLabel->SetText(str);
1335         pLabel->Draw();
1336
1337 CATCH:
1338         return r;
1339 }
1340
1341 result
1342 MultiForm::SetControlText(Button* pButton, const char* format, ...)
1343 {
1344         va_list ap;
1345         char text[256];
1346         String str;
1347         result r = E_SUCCESS;
1348
1349         TryCatch(pButton, r = E_INVALID_ARG, "pButton is null");
1350         va_start(ap, format);
1351         vsnprintf(text, sizeof(text), format, ap);
1352         va_end(ap);
1353         str = text;
1354         pButton->SetText(str);
1355         pButton->Draw();
1356
1357 CATCH:
1358         return r;
1359 }
1360
1361 result
1362 MultiForm::SetControlText(EditArea* pEditArea, const char* format, ...)
1363 {
1364         va_list ap;
1365         char text[1024];
1366         String str;
1367         result r = E_SUCCESS;
1368
1369         TryCatch(pEditArea, r = E_INVALID_ARG, "pEditArea is null");
1370         va_start(ap, format);
1371         vsnprintf(text, sizeof(text), format, ap);
1372         va_end(ap);
1373         str = text;
1374         pEditArea->SetText(str);
1375         pEditArea->SetCursorPosition(0);
1376         pEditArea->Draw();
1377
1378 CATCH:
1379         return r;
1380 }
1381
1382 result
1383 MultiForm::SetControlText(EditArea* pEditArea, const Tizen::Base::String& str)
1384 {
1385         result r = E_SUCCESS;
1386
1387         TryCatch(pEditArea, r = E_INVALID_ARG, "pEditArea is null");
1388         pEditArea->SetText(str);
1389         pEditArea->SetCursorPosition(0);
1390         pEditArea->Draw();
1391
1392 CATCH:
1393         return r;
1394 }
1395
1396 result
1397 MultiForm::AppendControlText(EditArea* pEditArea, const char* format, ...)
1398 {
1399         va_list ap;
1400         char text[256];
1401         String str;
1402         result r = E_SUCCESS;
1403
1404         TryCatch(pEditArea, r = E_INVALID_ARG, "pEditArea is null");
1405         va_start(ap, format);
1406         vsnprintf(text, sizeof(text), format, ap);
1407         va_end(ap);
1408         str = text;
1409         pEditArea->AppendText(str);
1410         pEditArea->SetCursorPosition(0);
1411         pEditArea->Draw();
1412
1413 CATCH:
1414         return r;
1415 }
1416
1417 result
1418 MultiForm::HideAndGetBounds(Tizen::Ui::Control* pCtrl, Tizen::Graphics::Rectangle& rect)
1419 {
1420         result r = E_SUCCESS;
1421         TryCatch(pCtrl, r = E_SYSTEM, "pCtrl is null");
1422         pCtrl->SetShowState(false);
1423         pCtrl->Draw();
1424
1425         rect = pCtrl->GetBounds();
1426
1427 CATCH:
1428         return r;
1429 }
1430
1431 void
1432 MultiForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
1433 {
1434         AppLog("MultiForm::OnFormBackRequested called");
1435 }
1436
1437 void
1438 MultiForm::OnOrientationChanged(const Tizen::Ui::Control& source, Tizen::Ui::OrientationStatus orientationStatus)
1439 {
1440         AppLog("MultiForm::OnOrientationChanged called %d", orientationStatus);
1441 }