Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / MediaApp / MediaApp / project / src / Image / ImageViewerForm.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.tizenopensource.org/license
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18
19 #include <FAppApp.h>
20 #include "BrowserForm.h"
21 #include "ImageViewerForm.h"
22 #include "ImageConverterForm.h"
23 #include "FIo.h"
24 #include "UnitTestFactory.h"
25 #include "AppConfig.h"
26 #include "PixelFormatMapper.h"
27
28 #define SECTION_NAME    L"ImageViewer"
29 #define PREV_INDEX 1
30 #define NEXT_INDEX 2
31 #define IV_FORM_LISTVIEW_H 250
32 #define IV_FORM_POPUP_W 400
33
34 using namespace Osp::Base;
35 using namespace Osp::Ui;
36 using namespace Osp::Ui::Controls;
37 using namespace Osp::Graphics;
38 using namespace Osp::Io;
39 using namespace Osp::App;
40
41 MULTI_FORM_REGISTER(ImageViewerForm, L"ImageViewerForm");
42 DECLARE_TC(L"Image", L"1.Image Viewer", ImageViewerForm::TestFunc, 0);
43
44 result
45 ImageViewerForm::TestFunc(void* pParam)
46 {
47         return MultiForm::ActivateForm(L"ImageViewerForm", pParam, MultiForm::GetCurrentForm(), null);
48 }
49
50 ImageViewerForm::ImageViewerForm(void)
51 {
52         __pBitmap = null;
53         __pContextMenu = null;
54         __pPopupPixFmt = null;
55         __pListViewPixFmt = null;
56         __pbtnPixFmtOK = null;
57         __currentListViewId = -1;
58         __pSettingItemArrayList = null;
59         __pixFmtIndex = 0;
60
61         __pLog = null;
62         __pBmpCtrl = null;
63
64         __srcWidth = 0;
65         __srcHeight = 0;
66         __fileSize = 0;
67         __pixelFmt = BITMAP_PIXEL_FORMAT_RGB565;
68
69 }
70
71 ImageViewerForm::~ImageViewerForm(void)
72 {
73         if (__pBitmap != null)
74         {
75                 delete __pBitmap;
76                 __pBitmap = null;
77         }
78
79         if (__pContextMenu != null)
80         {
81                 __pContextMenu->RemoveActionEventListener(*this);
82                 delete __pContextMenu;
83                 __pContextMenu = null;
84         }
85
86         if (__pPopupPixFmt != null)
87         {
88                 delete __pPopupPixFmt;
89                 __pPopupPixFmt = null;
90         }
91
92         if (__pSettingItemArrayList != null)
93         {
94                 delete[] __pSettingItemArrayList;
95                 __pSettingItemArrayList = null;
96         }
97
98 }
99
100 bool
101 ImageViewerForm::Initialize()
102 {
103         Construct(L"IDF_IMAGE_VIEWER");
104
105         return true;
106 }
107
108
109 result
110 ImageViewerForm::OnInitializing(void)
111 {
112         result r = E_SUCCESS;
113         String dirName;
114         String fullDirName;
115
116         r = __img.Construct();
117         if (r != E_SUCCESS)
118         {
119                 AppLogException("[%s] Failed to construct image instance.", GetErrorMessage(r));
120                 return r;
121         }
122
123         SetHeaderText("Image Viewer");
124         SetFooterStyle(FOOTER_STYLE_BUTTON_TEXT, ID_BACK, this);
125         r = AddFooterItem(L"Settings", ID_SETTING);
126         if (IsFailed(r))
127         {
128                 AppLogException("Failed to add \"Settings\" button.");
129                 return r;
130         }
131
132         __pixelFmt = BITMAP_PIXEL_FORMAT_RGB565;
133
134         AddFooterItem(L"Prev", ID_PREV);
135         AddFooterItem(L"Next", ID_NEXT);
136         SetStepInfo(0, 0, PREV_INDEX, NEXT_INDEX);
137
138         __pBmpCtrl = BitmapControl::ConstructN(GetControl(L"IDC_BUTTON_IMAGE"));
139         if (__pBmpCtrl == null)
140         {
141                 r = GetLastResult();
142                 AppLogException("BitmapControl::ConstructN failed:%s", GetErrorMessage(r));
143                 return r;
144         }
145         AddControl(*__pBmpCtrl);
146
147         __pLog = LogControl::ConstructN(GetControl(L"IDC_EDITAREA_INFO"));
148         if (__pLog == null)
149         {
150                 r = GetLastResult();
151                 AppLogException("LogControl::ConstructN failed:%s", GetErrorMessage(GetLastResult()));
152                 return r;
153         }
154         AddControl(*__pLog);
155         __pLog->SetEnabled(false);
156
157         FitControlBounds(*__pLog, __pBmpCtrl, GetFooter(), 2, 2, true);
158
159         r = ConstructContextMenu();
160         if (r != E_SUCCESS)
161         {
162                 AppLogException("Context menu construction failed: %s", GetErrorMessage(r));
163                 return r;
164         }
165         // Read files from directory. Arrange image files alphabetically.
166         dirName = __pConfig->GetString(SECTION_NAME, "loadPath");
167         fullDirName = App::GetInstance()->GetAppRootPath();
168         fullDirName.Append("data");
169         fullDirName.Append(dirName);
170
171         r = GetFilesList(fullDirName);
172         if (IsFailed(r))
173         {
174                 AppLogException("[%s] Could not get image files present in given directory %ls", GetErrorMessage(r), fullDirName.GetPointer());
175                 return r;
176         }
177
178         return r;
179 }
180
181 int
182 ImageViewerForm::GetItemCount(void)
183 {
184         AppLog("Enter here ");
185         switch (__currentListViewId)
186         {
187         case ID_BTN_PIXELFORMAT:
188         {
189                 if (__pSettingItemArrayList)
190                 {
191                         int count = __pSettingItemArrayList->GetCount();
192                         AppLog("count = %d", count);
193                         return count;
194                 }
195                 else
196                 {
197                         return 0;
198                 }
199         }
200         break;
201
202         default:
203                 return 0;
204         }
205 }
206
207 result
208 ImageViewerForm::AddListView(ListView** pListView, Popup* pPopup, int id)
209 {
210         result r = E_SUCCESS;
211         ListView* pCtrl = new (std::nothrow) ListView();
212         Rectangle popupRect = pPopup->GetClientAreaBounds();
213         if (pCtrl == null)
214         {
215                 r = E_FAILURE;
216                 goto FAIL;
217         }
218         //If listview height is lesser than popup area, use that height
219         if (popupRect.height > IV_FORM_LISTVIEW_H)
220         {
221                 popupRect.height = IV_FORM_LISTVIEW_H;
222         }
223         r = pCtrl->Construct(Rectangle(0, 0, popupRect.width, popupRect.height), true, false);
224         if (IsFailed(r))
225         {
226                 AppLogException("ListView construct failed.");
227                 SAFE_DELETE(pCtrl);
228                 goto FAIL;
229         }
230         __currentListViewId = id;
231         pCtrl->SetItemProvider(*this);
232         pCtrl->AddListViewItemEventListener(*this);
233         r = pPopup->AddControl(*pCtrl);
234         if (IsFailed(r))
235         {
236                 AppLogException("ListView AddControl failed.");
237                 SAFE_DELETE(pCtrl);
238                 goto FAIL;
239         }
240         *pListView = pCtrl;
241         return r;
242
243 FAIL:
244         return r;
245 }
246
247 void
248 ImageViewerForm::OnListViewItemSwept(Osp::Ui::Controls::ListView& listView, int index, Osp::Ui::Controls::SweepDirection direction)
249 {
250         AppLog("Enter here");
251 }
252 void
253 ImageViewerForm::OnListViewContextItemStateChanged(Osp::Ui::Controls::ListView& listView, int index, int elementId, Osp::Ui::Controls::ListContextItemStatus state)
254 {
255         AppLog("Enter here");
256 }
257
258 Osp::Ui::Controls::ListItemBase*
259 ImageViewerForm::CreateItem(int index, int itemWidth)
260 {
261         AppLog("Enter here index = %d", index);
262         ListAnnexStyle style = LIST_ANNEX_STYLE_RADIO;
263         result r = E_SUCCESS;
264         CustomItem* pItem = new (std::nothrow) CustomItem();
265         if (pItem == null)
266         {
267                 goto FAIL;
268         }
269
270         r = pItem->Construct(Osp::Graphics::Dimension(itemWidth, LISTVIEW_ITEM_HEIGHT), style);
271         if (IsFailed(r))
272         {
273                 AppLogException("Failed to construct listview.");
274                 return null;
275         }
276         switch (__currentListViewId)
277         {
278         case ID_BTN_PIXELFORMAT:
279         {
280                 if (__pSettingItemArrayList)
281                 {
282                         SettingListData* pItemValue = (SettingListData*) __pSettingItemArrayList->GetAt(index);
283                         if (pItemValue)
284                         {
285                                 r = pItem->AddElement(Rectangle(0, 0, itemWidth, LISTVIEW_ITEM_HEIGHT), pItemValue->elementId, *(pItemValue->pItemName), true);
286                                 if (IsFailed(r))
287                                 {
288                                         AppLogException("Could not create listview.");
289                                         goto FAIL;
290                                 }
291                         }
292
293                         if (index == (__pSettingItemArrayList->GetCount() - 1))
294                         {
295                                 __pSettingItemArrayList->RemoveAll(true);
296                                 delete __pSettingItemArrayList;
297                                 __pSettingItemArrayList = null;
298                         }
299                 }
300         }
301         break;
302
303         default:
304                 AppLogException("default case matching = %d", __currentListViewId);
305                 goto FAIL;
306                 break;
307         }
308
309         return pItem;
310
311 FAIL:
312         if (pItem)
313         {
314                 delete pItem;
315         }
316
317         return null;
318 }
319
320 bool
321 ImageViewerForm::DeleteItem(int index, Osp::Ui::Controls::ListItemBase* pItem, int itemWidth)
322 {
323         AppLog("Enter here");
324         delete pItem;
325         pItem = null;
326         return true;
327 }
328
329 void
330 ImageViewerForm::OnListViewItemStateChanged(Osp::Ui::Controls::ListView& source, int index, int elementId, Osp::Ui::Controls::ListItemStatus status)
331 {
332         AppLog("Enter here");
333         result r = E_SUCCESS;
334         if (&source == __pListViewPixFmt)
335         {
336                 __pListViewPixFmt->Draw();
337                 if (__pixFmtIndex == index)
338                 {
339                         r = __pListViewPixFmt->SetItemChecked(index, true);
340                         if (IsFailed(r))
341                         {
342                                 AppLogException("Failed to check item in listview.");
343                         }
344                         return;
345                 }
346
347                 r = __pListViewPixFmt->SetItemChecked(__pixFmtIndex, false);
348                 if (IsFailed(r))
349                 {
350                         AppLogException("SetItemChecked failed.");
351                 }
352
353                 __pixFmtIndex = index;
354         }
355
356         AppLog("ImageViewerForm PixelFormat = %d", __pixFmtIndex);
357         return;
358 }
359
360 result
361 ImageViewerForm::ConstructContextMenu(void)
362 {
363         result r = E_SUCCESS;
364
365         if (__pContextMenu == null)
366         {
367
368                 int x, y, width, height;
369                 __pContextMenu = new (std::nothrow) ContextMenu();
370
371                 if (__pContextMenu == null)
372                 {
373                         AppLogException("Failed to create \"Settings\" menu.");
374                         return E_OUT_OF_MEMORY;
375                 }
376                 // Get reference coordinates of context menu from footer.
377                 GetFooter()->GetBounds(x, y, width, height);
378
379                 r = __pContextMenu->Construct(Point(0, y), CONTEXT_MENU_STYLE_LIST);
380                 if (IsFailed(r))
381                 {
382                         AppLogException("Failed to construct \"Settings\" menu.");
383                         return r;
384                 }
385
386                 r = __pContextMenu->AddItem("PixelFormat", ID_MENU_PIXELFORMAT);
387                 if (IsFailed(r))
388                 {
389                         AppLogException("Failed to construct \"Settings\" menu.");
390                         return r;
391                 }
392                 __pContextMenu->AddActionEventListener(*this);
393         }
394         return r;
395 }
396
397 result
398 ImageViewerForm::OnActivate(void* param)
399 {
400         result r = E_SUCCESS;
401         String* pFileName = null;
402         int count;
403
404         AppLog("Enter");
405
406         __pLog->Clear();
407         __pBmpCtrl->Clear();
408
409         if (param)
410         {
411                 __pParam = (ImageViewerFormParam*) param;
412                 pFileName = &__pParam->srcFile;
413                 SetStepInfo(0, 0, PREV_INDEX, NEXT_INDEX);
414         }
415         else
416         {
417                 count = fileList.GetCount();
418                 pFileName = dynamic_cast< String* >(fileList.GetAt(0));
419                 SetStepInfo(count, 0, PREV_INDEX, NEXT_INDEX);
420         }
421
422         AppLog("filename: %ls", pFileName->GetPointer());
423         r = Process(*pFileName);
424         UpdateLog(r);
425         if (r != E_SUCCESS)
426         {
427                 AppLogException("Decode failed: %s", GetErrorMessage(r));
428                 return r;
429         }
430
431         r = ConstructContextMenu();
432         if (r != E_SUCCESS)
433         {
434                 AppLogException("Context menu construction failed: %s", GetErrorMessage(r));
435                 return r;
436         }
437
438         return E_SUCCESS;
439 }
440
441 void
442 ImageViewerForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
443 {
444         result r = E_SUCCESS;
445         String* pFileName = null;
446
447         switch (actionId)
448         {
449         case ID_BACK:
450         {
451                 AppLog("Go back to Browser form\n");
452                 __pLog->Clear();
453                 RemoveControl(*__pBmpCtrl);
454                 if (__pBitmap != null)
455                 {
456                         delete __pBitmap;
457                         __pBitmap = null;
458                 }
459                 Deactivate();
460         }
461         break;
462
463         case ID_PREV:
464         {
465                 int index = PrevStep();
466                 pFileName = dynamic_cast< String* >(fileList.GetAt(index));
467                 AppLog("%d filename:%ls", index, pFileName->GetPointer());
468                 r = Process(*pFileName);
469                 UpdateLog(r);
470         }
471         break;
472
473         case ID_NEXT:
474         {
475                 int index = NextStep();
476                 pFileName = dynamic_cast< String* >(fileList.GetAt(index));
477                 AppLog("%d filename:%ls", index, pFileName->GetPointer());
478                 r = Process(*pFileName);
479                 UpdateLog(r);
480         }
481         break;
482
483         case ID_SETTING:
484         {
485                 __pContextMenu->SetShowState(true);
486                 __pContextMenu->Show();
487         }
488         break;
489
490         case ID_MENU_PIXELFORMAT:
491         {
492                 CreatePixFmtMenu();
493         }
494         break;
495
496         case ID_BTN_PIXELFORMAT:
497         {
498                 BitmapPixelFormat pixelformats[2] = {BITMAP_PIXEL_FORMAT_RGB565, BITMAP_PIXEL_FORMAT_ARGB8888};
499                 HidePopUp(__pPopupPixFmt);
500                 __pPopupPixFmt = null;
501                 if (__pixelFmt != pixelformats[__pixFmtIndex])
502                 {
503                         __pixelFmt = pixelformats[__pixFmtIndex];
504                         int index = CurrStep();
505                         pFileName = dynamic_cast< String* >(fileList.GetAt(index));
506                         AppLog("%d filename:%ls", index, pFileName->GetPointer());
507                         r = Process(*pFileName);
508                         UpdateLog(r);
509                 }
510         }
511         break;
512
513         default:
514                 break;
515         }
516 }
517
518 result
519 ImageViewerForm::CreatePopUp(Popup** pPopupCtrl, String title, Dimension dimension, bool hasTitle)
520 {
521         result r = E_SUCCESS;
522         Popup* pCtrl = new (std::nothrow) Popup();
523         if (pCtrl == null)
524         {
525                 return E_OUT_OF_MEMORY;
526         }
527         *pPopupCtrl = pCtrl;
528         r = pCtrl->Construct(hasTitle, dimension);
529         if (IsFailed(r))
530         {
531                 AppLogException("popup construct failed.");
532                 goto FAIL;
533         }
534
535         if (hasTitle)
536         {
537                 r = pCtrl->SetTitleText(String(title));
538                 if (IsFailed(r))
539                 {
540                         AppLogException("popup SetTitleText failed.");
541                         goto FAIL;
542                 }
543         }
544         return r;
545 FAIL:
546         return r;
547
548 }
549 void
550 ImageViewerForm::DeletePopup(Popup* pPopup)
551 {
552         if (pPopup)
553         {
554                 delete pPopup;
555                 pPopup = null;
556         }
557 }
558
559 result
560 ImageViewerForm::AddButton(Button** pButtonCtrl, String text, int actionId, Popup* pPopup, Rectangle dimension)
561 {
562         result r = E_SUCCESS;
563         Button* pCtrl = new (std::nothrow) Button();
564         if (pCtrl == null)
565         {
566                 return E_OUT_OF_MEMORY;
567         }
568
569         r = pCtrl->Construct(dimension, text);
570         if (IsFailed(r))
571         {
572                 AppLogException("button construct failed.");
573                 SAFE_DELETE(pCtrl);
574                 goto FAIL;
575         }
576         pCtrl->SetActionId(actionId);
577         pCtrl->AddActionEventListener(*this);
578         r = pPopup->AddControl(*pCtrl);
579         if (IsFailed(r))
580         {
581                 AppLogException("popup AddControl failed.");
582                 SAFE_DELETE(pCtrl);
583                 goto FAIL;
584         }
585         *pButtonCtrl = pCtrl;
586         return r;
587
588 FAIL:
589         return r;
590 }
591
592 result
593 ImageViewerForm::ShowPopUp(Popup* pPopUp)
594 {
595         result r = E_SUCCESS;
596         if (pPopUp == null)
597         {
598                 goto FAIL;
599         }
600         r = pPopUp->SetShowState(true);
601         if (IsFailed(r))
602         {
603                 AppLogException("popup SetShowState failed.");
604                 goto FAIL;
605         }
606         r = pPopUp->Show();
607         if (IsFailed(r))
608         {
609                 AppLogException("popup Show failed.");
610                 goto FAIL;
611         }
612         return r;
613
614 FAIL:
615         return r;
616 }
617
618
619 void
620 ImageViewerForm::HidePopUp(Popup* pPopUp)
621 {
622         if (pPopUp == null)
623         {
624                 return;
625         }
626         pPopUp->SetShowState(false);
627         Draw();
628         return;
629 }
630
631 bool
632 ImageViewerForm::CreatePixFmtMenu()
633 {
634         result r = E_SUCCESS;
635
636         if (__pPopupPixFmt == null)
637         {
638                 String strTemp;
639                 Dimension dim(400, 400);
640                 Rectangle rect(120, 270, 120, 60);
641                 r = CreatePopUp(&__pPopupPixFmt, L"Select Pixelformat", dim, true);
642                 if (IsFailed(r))
643                 {
644                         goto FAIL;
645                 }
646
647                 r = AddButton(&__pbtnPixFmtOK, L"OK", ID_BTN_PIXELFORMAT, __pPopupPixFmt, rect);
648                 if (IsFailed(r))
649                 {
650                         goto FAIL;
651                 }
652
653                 if (__pSettingItemArrayList != null)
654                 {
655                         delete[] __pSettingItemArrayList;
656                         __pSettingItemArrayList = null;
657                 }
658
659                 __pSettingItemArrayList = new (std::nothrow) ArrayList;
660
661                 String* pPixFmtStrValue = new (std::nothrow) String(L"RGB565");
662                 SettingListData* pItemData = new (std::nothrow) SettingListData(pPixFmtStrValue, 0);
663                 __pSettingItemArrayList->Add(*pItemData);
664
665                 pPixFmtStrValue = new (std::nothrow) String(L"ARGB8888");
666                 pItemData = new (std::nothrow) SettingListData(pPixFmtStrValue, 1);
667                 __pSettingItemArrayList->Add(*pItemData);
668
669                 r = AddListView(&__pListViewPixFmt, __pPopupPixFmt, ID_BTN_PIXELFORMAT);
670                 if (IsFailed(r))
671                 {
672                         goto FAIL;
673                 }
674         }
675
676         ShowPopUp(__pPopupPixFmt);
677
678         __pListViewPixFmt->Draw();
679         __pListViewPixFmt->SetItemChecked(__pixFmtIndex, true);
680
681         return true;
682 FAIL:
683         SAFE_DELETE(__pPopupPixFmt);
684         AppLogException("%s", GetErrorMessage(r));
685
686         return false;
687 }
688
689 result
690 ImageViewerForm::Process(String filePath)
691 {
692         result r = E_SUCCESS;
693         File file;
694         ByteBuffer buffer;
695         FileAttributes attr;
696         String str;
697
698         AppLog("Reload: %ls", filePath.GetPointer());
699         ResetFileAtrributes();
700         __srcName = filePath;
701
702         if (__pBitmap != null)
703         {
704                 delete __pBitmap;
705                 __pBitmap = null;
706         }
707
708         r = Osp::Io::File::GetAttributes(filePath, attr);
709         if (r != E_SUCCESS)
710         {
711                 AppLogException("file.GetAttributes failed : %s", GetErrorMessage(r));
712                 return r;
713         }
714
715         __fileSize = attr.GetFileSize();
716
717         __pBitmap = __img.DecodeN(filePath, __pixelFmt);
718
719         if ((r = GetLastResult()) != E_SUCCESS)
720         {
721                 AppLog("ImageViewerForm::Process __img.DecodeN FAILED");
722                 filePath = App::GetInstance()->GetAppRootPath() + L"data/Image/decoding_failed.png";
723                 __pBitmap = __img.DecodeN(filePath, BITMAP_PIXEL_FORMAT_ARGB8888);
724         }
725
726         __srcWidth = __pBitmap->GetWidth();
727         __srcHeight = __pBitmap->GetHeight();
728         __imgFormat = __img.GetImageFormat(filePath);
729         __hasAlpha = __img.HasAlphaChannels(filePath);
730
731         return r;
732
733 }
734
735 void
736 ImageViewerForm::ResetFileAtrributes(void)
737 {
738         __srcWidth = 0;
739         __srcHeight = 0;
740         __fileSize = 0;
741         __imgFormat = IMG_FORMAT_NONE;
742         __hasAlpha = false;
743
744 }
745
746 result
747 ImageViewerForm::IsImageFile(String* pFileName)
748 {
749         ImageFormat format = IMG_FORMAT_NONE;
750
751         format = __img.GetImageFormat(*pFileName);
752         if (format != IMG_FORMAT_NONE)
753         {
754                 return E_SUCCESS;
755         }
756         return E_FAILURE;
757 }
758
759 result
760 ImageViewerForm::GetFilesList(String fullDirName)
761 {
762         Directory* pDir = null;
763         DirEnumerator* pDirEnum = null;
764         StringComparer strComparer;
765         result r = E_SUCCESS;
766
767         fileList.Construct();
768
769         pDir = new (std::nothrow) Directory();
770
771         r = pDir->Construct(fullDirName);
772         if (IsFailed(r))
773         {
774                 AppLogException("[%s] Failed to construct directory %S", GetErrorMessage(r), fullDirName.GetPointer());
775                 delete pDir;
776                 return r;
777         }
778
779         pDirEnum = pDir->ReadN();
780         if (pDirEnum == null)
781         {
782                 AppLogException("[%s] Failed to read entries from directory %S", GetErrorMessage(GetLastResult()), fullDirName.GetPointer());
783                 delete pDir;
784                 return r;
785         }
786
787         while (pDirEnum->MoveNext() == E_SUCCESS)
788         {
789                 DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
790                 if ((dirEntry.IsDirectory() == false) && (dirEntry.IsHidden() == false))
791                 {
792                         String* fullFileName = new (std::nothrow) String;
793                         fullFileName->Append(fullDirName);
794                         fullFileName->Append('/');
795                         String fileName(dirEntry.GetName());
796                         fullFileName->Append(fileName);
797
798                         r = IsImageFile(fullFileName);
799                         if (r == E_SUCCESS)
800                         {
801                                 fileList.Add(*fullFileName);
802                         }
803                         else
804                         {
805                                 delete fullFileName;
806                                 fullFileName = null;
807                         }
808                 }
809         }
810
811         fileList.Sort(strComparer);
812
813         delete pDir;
814         delete pDirEnum;
815
816         if (fileList.GetCount() >= 0)
817         {
818                 return E_SUCCESS;
819         }
820         else
821         {
822                 return E_FAILURE;
823         }
824 }
825
826 void
827 ImageViewerForm::UpdateLog(result r)
828 {
829         __pLog->Clear();
830         __pLog->Log(__srcName);
831         __pLog->Log("\nFileSize:%dKB\nDimension:%dx%d\nFormat:%s\nPixelFormat:%s\nAlphChannel:%s\nResult:%s",
832                                 __fileSize / 1000, __srcWidth, __srcHeight,
833                                 PixelFormatMapper::GetImageFormatString(__imgFormat),
834                                 __pixelFmt == BITMAP_PIXEL_FORMAT_RGB565 ? "RGB565" : "ARGB8888",
835                                 __hasAlpha ? "true" : "false",
836                                 GetErrorMessage(r));
837
838         __pBmpCtrl->Clear();
839         __pBmpCtrl->SetBitmap(*__pBitmap);
840         __pBmpCtrl->Draw();
841 }
842
843 void
844 ImageViewerForm::OnFormBackRequested(Osp::Ui::Controls::Form& source)
845 {
846         AppLog("ImageViewerForm::OnFormBackRequested called");
847         if (__pBitmap != null)
848         {
849                 delete __pBitmap;
850                 __pBitmap = null;
851         }
852         if (__pContextMenu != null)
853         {
854                 __pContextMenu->RemoveActionEventListener(*this);
855                 delete __pContextMenu;
856                 __pContextMenu = null;
857         }
858         Deactivate();
859 }