Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntArticleReaderForm.cpp
1 //
2
3 // Copyright (c) 2012 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 // !Internet
19 /*@file:    ArticleReaderForm.cpp
20  *@brief:       This header file contains the definitions of the ArticleReaderForm class.
21  *
22  */
23
24 #include <FApp.h>
25 #include <FBase.h>
26 #include "IntArticleReaderForm.h"
27 #include "IntCommonLib.h"
28 #include "IntSceneRegister.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
37 using namespace Tizen::Web::Controls;
38
39 static const wchar_t* IDB_SMALL_FONT = L"I01_font_button_left.png";
40 static const wchar_t* IDB_LARGE_FONT = L"I01_font_button_right.png";
41 static const wchar_t* IDB_FINDWORD_INPUT_FIELD_BG = L"I01_toolbar_input_field_findword.9.png";
42
43 const int ArticleReaderForm::IDA_MORE_BUTTON = 101;
44 const int ArticleReaderForm::IDA_BACK_BUTTON = 102;
45 const int ArticleReaderForm::IDA_SMALL_FONT_BUTTON = 103;
46 const int ArticleReaderForm::IDA_LARGE_FONT_BUTTON = 104;
47 const int ArticleReaderForm::IDA_SAVE_CLICKED = 105;
48 const int ArticleReaderForm::IDA_SHARE_CLICKED = 106;
49 const int ArticleReaderForm::IDA_PRINT_CLICKED = 107;
50 const int ArticleReaderForm::IDA_COPY_TEXT_CLICKED = 108;
51 const int ArticleReaderForm::IDA_FIND_TEXT_CLICKED = 109;
52 const int ArticleReaderForm::IDA_SHARE_TEXT_CLICKED = 110;
53 const int ArticleReaderForm::IDA_FINDWORD_CANCEL_CLICKED = 111;
54 const int ArticleReaderForm::IDA_FINDWORD_CLEAR_CLICKED = 112;
55 const int ArticleReaderForm::IDA_FINDWORD_NEXT_CLICKED = 113;
56 const int ArticleReaderForm::IDA_FINDWORD_PREV_CLICKED =114;
57
58 ArticleReaderForm::ArticleReaderForm(void):
59         __pWebReader(null)
60         ,__pFooterPanel(null)
61         ,__pMoreBtn(null)
62         ,__pBackBtn(null)
63         ,__pSmallFontBtn(null)
64         ,__pLargeFontBtn(null)
65         ,__pMoreMenu(null)
66         ,__pHitElementResult(null)
67         ,__pSelectionMenu(null)
68         ,__pPopUp(null)
69         ,__pFindWordBgLabel(null)
70         ,__pFindWordClear(null)
71         ,__pFindWordCountLabel(null)
72         ,__pFindWordControl(null)
73         ,__pFindWordEditField(null)
74         ,__pFindWordNext(null)
75         ,__pFindWordPrev(null)
76 {
77
78 }
79
80 ArticleReaderForm::~ArticleReaderForm(void)
81 {
82         //      RemoveAllControls();
83 }
84
85 bool
86 ArticleReaderForm::Initialize(void)
87 {
88         AppLog("ArticleReaderForm::Initialize entered");
89         Construct(L"IDL_ARTICLE_READER_FORM");
90         return true;
91 }
92
93 result
94 ArticleReaderForm::OnInitializing(void)
95 {
96         AppLog("ArticleReaderForm::OnInitializing entered");
97         result r = E_SUCCESS;
98         WebSetting settings;
99
100         SceneManager* pSceneManager = SceneManager::GetInstance();
101         if (pSceneManager == null)
102         {
103                 return E_FAILURE;
104         }
105         pSceneManager->AddSceneEventListener(IDSCN_ARTICLE_READER, *this);
106
107         __pFooterPanel = static_cast<Panel*>(GetControl("IDC_PANEL1",true));
108         if(__pFooterPanel == null)
109         {
110                 AppLog("GetControl failed for FooterPanel button");
111                 return E_FAILURE;
112         }
113
114         __pWebReader = new (std::nothrow) Web();
115         __pWebReader->Construct(Rectangle(0,0, GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
116
117         settings.SetInputStyle(INPUT_STYLE_OVERLAY);
118         settings.SetFontSize(24/*SettingPresentationModel::GetInstance()->GetReaderFontSize()*/);
119
120         r = __pWebReader->SetSetting(settings);
121         AddControl(__pWebReader);
122         SetControlAlwaysAtBottom(*__pWebReader,true);
123         __pWebReader->LoadUrl("http://google.com");//temporary only for testing
124         if (IsFailed(r))
125                 AppLogDebug("Web setting add failed with %s", GetErrorMessage(r));
126
127         __pWebReader->AddTouchEventListener(*this);
128         __pWebReader->SetWebUiEventListener(this);
129         __pWebReader->SetTextSearchListener(this);
130         __pMoreBtn = static_cast<Button*>(GetControl("IDC_MORE_BUTTON",true));
131         if(__pMoreBtn == null)
132         {
133                 AppLog("GetControl failed for more button");
134                 return E_FAILURE;
135         }
136         __pMoreBtn->AddActionEventListener(*this);
137         __pMoreBtn->SetActionId(IDA_MORE_BUTTON);
138
139
140         __pBackBtn = static_cast<Button*>(GetControl("IDC_BACK_BUTTON",true));
141         if(__pBackBtn == null)
142         {
143                 AppLog("GetControl failed for back button");
144                 return E_FAILURE;
145         }
146         __pBackBtn->AddActionEventListener(*this);
147         __pBackBtn->SetActionId(IDA_BACK_BUTTON);
148
149
150         __pSmallFontBtn = static_cast<Button*>(GetControl("IDC_SMALL_FONT_BUTTON",true));
151         if(__pSmallFontBtn == null)
152         {
153                 AppLog("GetControl failed for small font button");
154                 return E_FAILURE;
155         }
156         __pSmallFontBtn->AddActionEventListener(*this);
157         __pSmallFontBtn->SetActionId(IDA_SMALL_FONT_BUTTON);
158         __pSmallFontBtn->SetEnabled(false);
159
160
161         __pLargeFontBtn = static_cast<Button*>(GetControl("IDC_LARGE_FONT_BUTTON",true));
162         if(__pLargeFontBtn == null)
163         {
164                 AppLog("GetControl failed for large font button");
165                 return E_FAILURE;
166         }
167         __pLargeFontBtn->AddActionEventListener(*this);
168         __pLargeFontBtn->SetActionId(IDA_LARGE_FONT_BUTTON);
169
170         AddOrientationEventListener(*this);
171
172         return r;
173 }
174
175 result
176 ArticleReaderForm::OnTerminating(void)
177 {
178         AppLog("ArticleReaderForm::OnTerminating entered");
179         result r = E_SUCCESS;
180         return r;
181 }
182
183 void
184 ArticleReaderForm::OnActionPerformed(const Control& source, int actionId)
185 {
186         AppLog("ArticleReaderForm::OnActionPerformed entered actionId %d",actionId);
187
188         SceneManager* pSceneManager = SceneManager::GetInstance();
189         result r = E_SUCCESS;
190
191         if (pSceneManager == null)
192         {
193                 return ;
194         }
195
196         switch (actionId)
197         {
198         case IDA_MORE_BUTTON:
199         {
200                 if(__pMoreMenu != null)
201                 {
202                         delete __pMoreMenu;
203                         __pMoreMenu = null;
204                 }
205                 __pMoreMenu = new(std::nothrow) ContextMenu();
206                 r = __pMoreMenu->Construct(Point(50,GetClientAreaBounds().height),CONTEXT_MENU_STYLE_LIST,CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
207
208                 TryCatch(!IsFailed(r),,"Contextmenu creation failed with%s",GetErrorMessage(r));
209
210                 __pMoreMenu->AddItem(CommonUtil::GetString(L"IDS_COM_SK_SAVE"),IDA_SAVE_CLICKED);
211                 __pMoreMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_CLICKED);
212                 __pMoreMenu->AddItem(CommonUtil::GetString(L"IDS_COM_SK_PRINT"),IDA_PRINT_CLICKED);
213                 __pMoreMenu->SetMaxVisibleItemsCount(3);
214                 __pMoreMenu->SetShowState(true);
215                 __pMoreMenu->Show();
216                 __pMoreMenu->Invalidate(true);
217                 __pMoreMenu->AddActionEventListener(*this);
218                 SetControlAlwaysOnTop(*__pMoreMenu, true);
219         }
220         break;
221
222         case IDA_BACK_BUTTON:
223         {
224                 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
225         }
226         break;
227         case IDA_SMALL_FONT_BUTTON:
228         {
229                 WebSetting setting = __pWebReader->GetSetting();
230                 setting.SetFontSize(24);
231
232                 __pWebReader->SetSetting(setting);
233                 __pSmallFontBtn->SetEnabled(false);
234                 __pSmallFontBtn->Invalidate(true);
235
236                 __pLargeFontBtn->SetEnabled(true);
237                 __pLargeFontBtn->Invalidate(true);
238         }
239         break;
240         case IDA_LARGE_FONT_BUTTON:
241         {
242                 WebSetting setting = __pWebReader->GetSetting();
243                 setting.SetFontSize(32);
244                 __pWebReader->SetSetting(setting);
245
246                 __pLargeFontBtn->SetEnabled(false);
247                 __pLargeFontBtn->Invalidate(true);
248
249                 __pSmallFontBtn->SetEnabled(true);
250                 __pSmallFontBtn->Invalidate(true);
251
252         }
253         break;
254         case IDA_SAVE_CLICKED:
255         {
256                 if(__pWebReader !=null)
257                 {
258                         r = __pWebReader->SavePageAsPdf(UiApp::GetInstance()->GetAppRootPath()+"//data//test.pdf");
259                         AppLog("SavePageAsPdf result %s",GetErrorMessage(r));
260
261                         int __modalMsgBoxResult;
262                         MessageBox* pMsgBox = new MessageBox();
263                         pMsgBox->Construct("Saved","Saved at "+UiApp::GetInstance()->GetAppRootPath()+"//data//test.pdf",MSGBOX_STYLE_OK,3000);
264                         pMsgBox->ShowAndWait(__modalMsgBoxResult);
265                         delete pMsgBox;
266                         pMsgBox = null;
267                         __modalMsgBoxResult = 0;
268                 }
269
270         }
271         break;
272         case IDA_SHARE_CLICKED:
273         {
274                 if(__pPopUp != null)
275                 {
276                         delete __pPopUp;
277                         __pPopUp = null;
278                 }
279                 __pPopUp = new(std::nothrow) SharePopup();
280                 __pPopUp->Initialize();
281
282                 ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
283                 pShareInfo->SetPageTitle(L"Google");//temporary only for testing
284                 pShareInfo->SetPageUrl(L"http://www.google.com");//temporary only for testing
285                 pShareInfo->SetImageAttached(false);
286                 __pPopUp->RemoveAllShareInfo();
287                 __pPopUp->AddShareInfo(pShareInfo);
288
289                 __pPopUp->SetShowState(true);
290                 __pPopUp->Show();
291         }
292         break;
293         case IDA_PRINT_CLICKED:
294         {
295                 r = __pWebReader->SavePageAsPdf(UiApp::GetInstance()->GetAppRootPath()+"//data//test.pdf");
296                 AppLog("SavePageAsPdf result %s",GetErrorMessage(r));
297
298                 AppLog("RequestPrint called!");
299                 AppControl* pAc = Tizen::App::AppManager::FindAppControlN(L"org.tizen.mobileprint", L"http://tizen.org/appcontrol/operation/print");
300                 result nResult = E_FAILURE;
301                 if (pAc)
302                 {
303                         AppLog("TestPrint if (pAc) == true");
304
305                         HashMap map;
306                         map.Construct();
307
308                         String fileType = L"service_print_files_type";
309                         String typeVal = L"DOC";
310
311                         String fileCount = L"service_print_files_count";
312                         String countVal = L"1";
313                         String fileFolder= L"service_print_files_folder_name";
314                         String folderVal = UiApp::GetInstance()->GetAppRootPath()+"//data";
315
316                         map.Add(&fileCount, &countVal);
317                         map.Add(&fileFolder, &folderVal);
318                         map.Add(&fileType, &typeVal);
319
320                         String fileName = L"service_print_files_files_name";
321
322                         ArrayList fileNameList;
323                         fileNameList.Construct();
324                         String file1 = L"test.pdf";
325
326                         fileNameList.Add(&file1);
327                         map.Add(&fileName, &fileNameList);
328
329                         nResult = pAc->Start(NULL, NULL, &map, NULL);
330
331                         if (nResult == E_SUCCESS) AppLog("TestPrint ret == E_SUCCESS");
332                         else if (nResult == E_MAX_EXCEEDED)
333                                 AppLog("TestPrint ret == E_MAX_EXCEEDED");
334                         else if (nResult == E_OBJ_NOT_FOUND)
335                                 AppLog("TestPrint ret == E_OBJ_NOT_FOUND");
336                         else if (nResult == E_IN_PROGRESS)
337                                 AppLog("TestPrint ret == E_IN_PROGRESS");
338                         else if (nResult == E_PRIVILEGE_DENIED)
339                                 AppLog("TestPrint ret == E_PRIVILEGE_DENIED");
340                         else if(nResult == E_SYSTEM)
341                                 AppLog("TestPrint ret == E_SYSTEM");
342
343                         delete pAc;
344                 }
345                 else
346                 {
347                         int __modalMsgBoxResult;
348                         MessageBox* pMsgBox = new MessageBox();
349                         pMsgBox->Construct("Not Supported","Not Supported",MSGBOX_STYLE_OK,3000);
350                         pMsgBox->ShowAndWait(__modalMsgBoxResult);
351                         delete pMsgBox;
352                         pMsgBox = null;
353                         __modalMsgBoxResult = 0;
354                 }
355         }
356         break;
357         case IDA_COPY_TEXT_CLICKED:
358         {
359                 __pWebReader->ReleaseBlock();
360                 // Sets data to a clip board item
361                 ClipboardItem item;
362                 String resourcePath = App::GetInstance()->GetAppResourcePath();
363                 item.Construct(CLIPBOARD_DATA_TYPE_TEXT, __pWebReader->GetTextFromBlock());
364
365                 // copying the item to clipboard
366                 Clipboard* pClipboard = Clipboard::GetInstance();
367                 if (pClipboard != null)
368                 {
369                         pClipboard->CopyItem(item);
370                 }
371         }
372         break;
373         case IDA_FIND_TEXT_CLICKED:
374         {
375                 InitFindWordPanel();
376                 __pWebReader->SetBounds(0,__pFindWordControl->GetHeight(),GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight() - __pFindWordControl->GetHeight());
377         }
378         break;
379         case IDA_SHARE_TEXT_CLICKED:
380         {
381                 AppLogDebug("IDA_SHARE_TEXT_CLICKED");
382                 if(__pPopUp != null)
383                 {
384                         delete __pPopUp;
385                         __pPopUp = null;
386                 }
387                 __pPopUp = new(std::nothrow) SharePopup();
388                 __pPopUp->Initialize();
389                 if (__pHitElementResult != null)
390                 {
391                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
392                         pShareInfo->SetPageTitle(L"");
393                         pShareInfo->SetPageUrl(__pWebReader->GetTextFromBlock());
394                         pShareInfo->SetImageAttached(false);
395                         __pPopUp->RemoveAllShareInfo();
396                         __pPopUp->AddShareInfo(pShareInfo);
397                         __pPopUp->SetShowState(true);
398                         __pPopUp->Show();
399                 }
400         }
401         break;
402
403         case IDA_FINDWORD_CANCEL_CLICKED:
404         {
405 //              __currentSearchStr = L"";
406 //              __currentWordIndex = 0;
407 //              __maxOccurrances = 0;
408                 __pFindWordEditField->SetText(L"");
409                 __pFindWordNext->SetEnabled(false);
410                 __pFindWordPrev->SetEnabled(false);
411                 __pFindWordCountLabel->SetText(L"0/0");
412                 __pWebReader->SearchText(L"aaaabbbbcccc",true);
413                 __pFooterPanel->SetShowState(true);
414                 __pFindWordControl->SetShowState(false);
415                 RelayoutControls();
416
417         }
418         break;
419         case IDA_FINDWORD_CLEAR_CLICKED:
420         {
421
422         }
423         break;
424         case IDA_FINDWORD_NEXT_CLICKED:
425         {
426
427         }
428         break;
429         case IDA_FINDWORD_PREV_CLICKED:
430         {
431
432         }
433         break;
434         default:
435                 break;
436         }
437
438         CATCH: return;
439 }
440
441 void
442 ArticleReaderForm::OnKeypadOpened(Tizen::Ui::Control& source)
443 {
444         __pFooterPanel->SetShowState(false);
445 }
446
447 void
448 ArticleReaderForm::OnKeypadClosed(Tizen::Ui::Control& source)
449 {
450         __pFooterPanel->SetShowState(true);
451         RelayoutControls();
452 }
453
454 void
455 ArticleReaderForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
456 {
457         AppLog("ArticleReaderForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
458
459         if (__pHitElementResult != null)
460         {
461                 delete __pHitElementResult;
462                 __pHitElementResult = null;
463         }
464
465         if (__pWebReader != null)
466         {
467                 AppLog("ArticleReaderForm::OnTouchLongPressed web not null");
468                 __pHitElementResult = __pWebReader->GetElementByPointN(currentPosition);
469         }
470
471         if (__pHitElementResult == null)
472         {
473                 return;
474         }
475
476         if (__pHitElementResult->HasImage() == true)
477         {
478
479         }
480         else if(__pHitElementResult->HasUrl() == true)
481         {
482
483         }
484         else
485         {
486                 String tagName = __pHitElementResult->GetTagName();
487                 String type = __pHitElementResult->GetAttributeValue("type");
488                 String value = __pHitElementResult->GetAttributeValue(L"value");
489                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
490
491                 result r =__pWebReader->SetBlockSelectionPosition(currentPosition);
492                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
493
494         }
495 //      __inputEventToBeSupressed = true;
496 }
497
498 void
499 ArticleReaderForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
500 {
501         AppLog("ArticleReaderForm::OnSceneActivatedN entered");
502 }
503
504 void
505 ArticleReaderForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
506 {
507         AppLog("ArticleReaderForm::OnSceneDeactivated entered");
508 }
509
510 void
511 ArticleReaderForm::OnTextFound(int totalCount, int currentOrdinal)
512 {
513         AppLog("ArticleReaderForm::OnTextFound totalCount %d",totalCount);
514         AppLog("ArticleReaderForm::OnTextFound currentOrdinal %d",currentOrdinal);
515
516         if(totalCount == -1 || totalCount == 0)
517         {
518                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
519                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
520         }
521         else if(totalCount > 100)
522         {
523                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
524                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
525         }
526         else
527         {
528                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
529                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
530         }
531
532         if (totalCount <= 0)
533         {
534                 __pFindWordNext->SetEnabled(false);
535         }
536         else
537         {
538                 __pFindWordNext->SetEnabled(true);
539         }
540
541         String countStr = L"";
542         countStr.Append(currentOrdinal);
543         countStr.Append(L"/");
544         countStr.Append(totalCount);
545         __pFindWordCountLabel->SetText(countStr);
546         __pFindWordCountLabel->Invalidate(false);
547
548         //FindNextWord(true);
549         //Update the controls
550         __pFindWordNext->Invalidate(false);
551 }
552
553 void
554 ArticleReaderForm::OnWebPageBlockSelected(Tizen::Web::Controls::Web& source, Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint)
555 {
556         AppLog("ArticleReaderForm::OnWebPageBlockSelected");
557         if (__pHitElementResult != null)
558         {
559                 delete __pHitElementResult;
560                 __pHitElementResult = null;
561         }
562
563         if (__pWebReader != null)
564         {
565                 AppLog("ArticleReaderForm::OnWebPageBlockSelected web not null");
566                 __pHitElementResult = __pWebReader->GetElementByPointN(startPoint);
567                 if(GetLastResult() == E_INVALID_ARG)
568                 {
569                         __pHitElementResult = __pWebReader->GetElementByPointN(endPoint);
570                 }
571         }
572
573         if (__pHitElementResult == null)
574         {
575                 return;
576         }
577
578         if (__pHitElementResult->HasImage() != true)
579         {
580                 String tagName = __pHitElementResult->GetTagName();
581                 String type = __pHitElementResult->GetAttributeValue("type");
582
583
584                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0))
585                 {
586
587                 }
588                 else
589                 {
590                         AppLog("ArticleReaderForm::OnWebPageBlockSelected no paste option");
591
592                         if(__pHitElementResult->GetUrl().GetLength() > 0)
593                         {
594                         }
595                         InitSelectTextContextMenu(endPoint);
596                         __pSelectionMenu->SetShowState(true);
597                         __pSelectionMenu->Show();
598                         __pSelectionMenu->Invalidate(true);
599                 }
600
601                 AppLog("ArticleReaderForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
602                 AppLog("ArticleReaderForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
603         }
604
605 }
606
607 void
608 ArticleReaderForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
609 {
610         AppLog("ArticleReaderForm::OnOrientationChanged entered");
611         if(__pFindWordControl)
612         {
613                 if (__pFindWordBgLabel != null)
614                 {
615                         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
616                         if (pBitmap != null)
617                         {
618                                 __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
619                                 delete pBitmap;
620                         }
621                 }
622
623                 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
624         }
625         RelayoutControls();
626 }
627
628
629 void
630 ArticleReaderForm::OnTextValueChanged (const Tizen::Ui::Control &source)
631 {
632
633         if (__pFindWordEditField != null)
634         {
635                 __pFindWordNext->SetEnabled(false);
636                 __pFindWordPrev->SetEnabled(false);
637                 __pFindWordNext->Invalidate(true);
638                 __pFindWordPrev->Invalidate(true);
639                 __pFindWordCountLabel->SetText(L"0/0");
640                 __pFindWordCountLabel->Invalidate(true);
641         }
642         if (__pFindWordEditField->GetText().GetLength() > 0)
643         {
644                 StartWordSearch();
645         }
646         else
647         {
648                 __pFindWordPrev->SetEnabled(false);
649                 __pWebReader->SearchText(L"aaaaaaaabbbbbbbccccccc");
650         }
651
652 //      else
653 //      {
654 ////            __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
655 //              StartWordSearch();
656 ////            __currentSearchStr = L"";
657 //              AppLogDebug("Enter something");
658 //      }
659 }
660
661 result
662 ArticleReaderForm::InitSelectTextContextMenu(Tizen::Graphics::Point p)
663 {
664         result r = E_SUCCESS;
665         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
666
667         AppLog("ArticleReaderForm::InitSelectTextContextMenu clicked on text");
668         if (__pSelectionMenu != null)
669         {
670                 delete __pSelectionMenu;
671                 __pSelectionMenu = null;
672         }
673
674         if(p.y < 150)
675         {
676                 p.y = p.y + 50;
677                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
678         }
679         else
680         {
681                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
682         }
683         __pSelectionMenu = new (std::nothrow) ContextMenu();
684         r = __pSelectionMenu->Construct(p, CONTEXT_MENU_STYLE_GRID, direction);
685         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
686
687         r = __pSelectionMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_COPY"),IDA_COPY_TEXT_CLICKED);
688         r = __pSelectionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"),IDA_FIND_TEXT_CLICKED);
689         r = __pSelectionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_TEXT_CLICKED);
690
691         __pSelectionMenu->SetMaxVisibleItemsCount(3);
692         __pSelectionMenu->AddActionEventListener(*this);
693         SetControlAlwaysOnTop(*__pSelectionMenu, true);
694
695         CATCH: return r;
696
697 }
698
699 result
700 ArticleReaderForm::InitFindWordPanel(void)
701 {
702         result r = E_SUCCESS;
703         Bitmap *pIconBitmap = null;
704
705         if (__pFindWordControl != null)
706         {
707                 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
708                 __pFindWordControl->SetShowState(true);
709                 __pFindWordEditField->SetText(__pWebReader->GetTextFromBlock());
710
711
712                 __pFindWordEditField->SetFocus();
713
714                 if (__pFindWordEditField->GetText().GetLength() > 0)
715                 {
716                         StartWordSearch();
717                 }
718                 return r;
719         }
720
721         __pFindWordControl = new (std::nothrow) Panel();
722         r = __pFindWordControl->Construct(L"IDL_FIND_ON_PAGE");
723         if (IsFailed(r))
724         {
725                 AppLogException("There is some problem in the xml file. Please check.");
726                 return E_FAILURE;
727         }
728         AddControl(__pFindWordControl);
729         __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
730         SetControlAlwaysOnTop(*__pFindWordControl,true);
731         __pFindWordControl->SetShowState(true);
732         __pFindWordControl->Invalidate(false);
733
734         __pFindWordBgLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_LABEL1", true));
735         if (__pFindWordBgLabel != null)
736         {
737                 Panel* pPanel1 = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL1", true));
738                 Rectangle pRect = pPanel1->GetBounds();
739                 pRect.x = pRect.y = 0;
740                 __pFindWordBgLabel->SetBounds(pRect);
741                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_search_input_field_bg.9.png", __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
742                 if (pBitmap != null)
743                 {
744                         AppLogDebug("InitFindWordPanel: Coming here");
745                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
746                         delete pBitmap;
747                 }
748                 else
749                 {
750                         AppLogDebug("InitFindWordPanel: shouldn't Come here");
751                 }
752         }
753
754         Button* pfindWordCancel = null;
755         pfindWordCancel = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CANCEL", true));
756         if (pfindWordCancel == null)
757         {
758                 AppLogException("There is some problem in the xml file. Please check.");
759                 return E_FAILURE;
760         }
761         pfindWordCancel->SetActionId(IDA_FINDWORD_CANCEL_CLICKED);
762         pfindWordCancel->AddActionEventListener(*this);
763
764         __pFindWordClear = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CLEAR", true));
765         if (__pFindWordClear == null)
766         {
767                 AppLogException("There is some problem in the xml file. Please check.");
768                 return E_FAILURE;
769         }
770
771         __pFindWordClear->SetActionId(IDA_FINDWORD_CLEAR_CLICKED);
772         __pFindWordClear->AddActionEventListener(*this);
773
774         __pFindWordNext = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_NEXT", true));
775         if (__pFindWordNext == null)
776         {
777                 AppLogException("There is some problem in the xml file. Please check.");
778                 return E_FAILURE;
779         }
780
781         __pFindWordNext->SetActionId(IDA_FINDWORD_NEXT_CLICKED);
782         __pFindWordNext->AddActionEventListener(*this);
783
784         __pFindWordPrev = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_PREV", true));
785         if (__pFindWordPrev == null)
786         {
787                 AppLogException("There is some problem in the xml file. Please check.");
788                 return E_FAILURE;
789         }
790
791         __pFindWordPrev->SetActionId(IDA_FINDWORD_PREV_CLICKED);
792         __pFindWordPrev->AddActionEventListener(*this);
793
794         __pFindWordNext->SetEnabled(false);
795         __pFindWordPrev->SetEnabled(false);
796
797         __pFindWordCountLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_FIND_COUNT_LABEL", true));
798         if (__pFindWordCountLabel == null)
799         {
800                 AppLogException("There is some problem in the xml file. Please check.");
801                 return E_FAILURE;
802         }
803
804         __pFindWordEditField = static_cast<EditField*>(__pFindWordControl->GetControl(L"IDC_FIND_WORD_EDITFIELD", true));
805         if (__pFindWordEditField == null)
806         {
807                 AppLogException("There is some problem in the xml file. Please check.");
808                 return E_FAILURE;
809         }
810         __pFindWordEditField->SetText(__pWebReader->GetTextFromBlock());
811         __pFindWordEditField->AddTextEventListener(*this);
812         __pFindWordEditField->AddKeypadEventListener(*this);
813         __pFindWordEditField->SetOverlayKeypadCommandButtonVisible(false);
814
815         __pFindWordEditField->SetFocus();
816 //      __pFindWordEditField->ShowKeypad();
817         if (__pFindWordEditField->GetText().GetLength() > 0)
818         {
819                 StartWordSearch();
820         }
821         return r;
822 }
823
824 void
825 ArticleReaderForm::StartWordSearch()
826 {
827         __pFindWordPrev->SetEnabled(false);
828         __pWebReader->SearchTextAllAsync(__pFindWordEditField->GetText(), false);
829
830 }
831
832 void
833 ArticleReaderForm::RelayoutControls()
834 {
835         if( __pFindWordControl && __pFindWordControl->GetShowState() == true)
836         {
837                 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
838                 __pWebReader->SetBounds(0,__pFindWordControl->GetHeight(),GetClientAreaBounds().width, GetClientAreaBounds().height - __pFooterPanel->GetHeight() - __pFindWordControl->GetHeight());
839         }
840         else
841         {
842                 if(__pWebReader)
843                         __pWebReader->SetBounds(0,0,GetClientAreaBounds().width, GetClientAreaBounds().height - __pFooterPanel->GetHeight());
844         }
845 }