Fixed Nabi issue N_SE-40542,N_SE-39949,N_SE-40229
[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(*__pShareTitle);
284                 pShareInfo->SetPageUrl(*__pShareUrl);
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
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                 __pWebReader->ReleaseBlock();
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                 __randomValue = true;
376                 InitFindWordPanel();
377                 RelayoutControls();
378 //              __pWebReader->SetBounds(0,__pFindWordControl->GetHeight(),GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight() - __pFindWordControl->GetHeight());
379         }
380         break;
381         case IDA_SHARE_TEXT_CLICKED:
382         {
383                 AppLogDebug("IDA_SHARE_TEXT_CLICKED");
384                 if(__pPopUp != null)
385                 {
386                         delete __pPopUp;
387                         __pPopUp = null;
388                 }
389                 __pPopUp = new(std::nothrow) SharePopup();
390                 __pPopUp->Initialize();
391                 if (__pHitElementResult != null)
392                 {
393                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
394                         pShareInfo->SetPageTitle(L"");
395                         pShareInfo->SetPageUrl(__pWebReader->GetTextFromBlock());
396                         pShareInfo->SetImageAttached(false);
397                         __pPopUp->RemoveAllShareInfo();
398                         __pPopUp->AddShareInfo(pShareInfo);
399                         __pPopUp->SetShowState(true);
400                         __pPopUp->Show();
401                 }
402         }
403         break;
404
405         case IDA_FINDWORD_CANCEL_CLICKED:
406         {
407 //              currentSearchStr = L"";
408 //              currentWordIndex = 0;
409 //              maxOccurances = 0;
410                 __pFindWordEditField->SetText(L"");
411                 __pFindWordNext->SetEnabled(false);
412                 __pFindWordPrev->SetEnabled(false);
413                 __pFindWordCountLabel->SetText(L"0/0");
414                 __pWebReader->SearchText(L"aaaabbbbcccc",true);
415                 __pFooterPanel->SetShowState(true);
416                 __pFindWordControl->SetShowState(false);
417                 RelayoutControls();
418
419         }
420         break;
421         case IDA_FINDWORD_CLEAR_CLICKED:
422         {
423                 __pFindWordCountLabel->SetText(L"0/0");
424                 __pFindWordEditField->SetText(L"");
425                 __pFindWordPrev->SetEnabled(false);
426                 __pWebReader->SearchText(L"aaaaaabbbbbbccccccc");
427                 __pFindWordNext->SetEnabled(false);
428                 __pFindWordControl->Invalidate(true);
429         }
430         break;
431         case IDA_FINDWORD_NEXT_CLICKED:
432         {
433                 FindNextWord(true);
434         }
435         break;
436         case IDA_FINDWORD_PREV_CLICKED:
437         {
438                 FindNextWord(false);
439         }
440         break;
441         break;
442         default:
443                 break;
444         }
445
446         CATCH: return;
447 }
448
449 void
450 ArticleReaderForm::OnKeypadOpened(Tizen::Ui::Control& source)
451 {
452         __pFooterPanel->SetShowState(false);
453 }
454
455 void
456 ArticleReaderForm::OnKeypadClosed(Tizen::Ui::Control& source)
457 {
458         __pFooterPanel->SetShowState(true);
459         RelayoutControls();
460 }
461
462 void
463 ArticleReaderForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
464 {
465         AppLog("ArticleReaderForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
466
467         if (__pHitElementResult != null)
468         {
469                 delete __pHitElementResult;
470                 __pHitElementResult = null;
471         }
472
473         if (__pWebReader != null)
474         {
475                 AppLog("ArticleReaderForm::OnTouchLongPressed web not null");
476                 __pHitElementResult = __pWebReader->GetElementByPointN(currentPosition);
477         }
478
479         if (__pHitElementResult == null)
480         {
481                 return;
482         }
483
484         if (__pHitElementResult->HasImage() == true)
485         {
486
487         }
488         else if(__pHitElementResult->HasUrl() == true)
489         {
490
491         }
492         else
493         {
494                 String tagName = __pHitElementResult->GetTagName();
495                 String type = __pHitElementResult->GetAttributeValue("type");
496                 String value = __pHitElementResult->GetAttributeValue(L"value");
497                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
498
499                 result r =__pWebReader->SetBlockSelectionPosition(currentPosition);
500                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
501
502         }
503 //      __inputEventToBeSupressed = true;
504 }
505
506 void
507 ArticleReaderForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
508 {
509         AppLog("ArticleReaderForm::OnSceneActivatedN entered");
510         int index = 0;
511         __pReaderData = static_cast<String*>(pArgs->GetAt(index++));
512         __pShareUrl = static_cast<String*>(pArgs->GetAt(index++));
513         __pShareTitle = static_cast<String*>(pArgs->GetAt(index++));
514         AppLog("ArticleReaderForm::OnSceneActivatedN __pReaderData %ls",__pReaderData->GetPointer());
515
516         String loadData = L"<html>\
517                                         <head>\
518                                         <meta name='viewport' content='width=device-width*0.73,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'>\
519                                         <style>\
520                                         h1\
521                                         {\
522                                         font-weight:bold;\
523                                         background-color: transparent;\
524                                         }\
525                                         div\
526                                         {\
527                                         display: block;\
528                                         }\
529                                         p\
530                                         {\
531                                         display: block; \
532                                         }\
533                                         img\
534                                         {\
535                                         margin-left:auto;\
536                                         margin-right:auto;\
537                                         }\
538                                         \
539                                         \
540                                         </style>\
541                                         </head>\
542                                         <body style='width:'";
543         loadData.Append(GetClientAreaBounds().width);
544         loadData.Append(L"px'>");
545         AppLogDebug("data->GetLength %d",__pReaderData->GetLength());
546         loadData.Append(*__pReaderData);
547         loadData.Append(L"</body></html>");
548
549         ByteBuffer buf ;
550         buf.Construct(loadData.GetLength());
551         AppLogDebug("data->GetLength %d",loadData.GetLength());
552         for (int z=0;z<loadData.GetLength();z++)
553         {
554                 mchar b;
555                 loadData.GetCharAt(z,b);
556                 buf.SetByte((byte)b);
557         }
558
559         buf.Flip();
560         if (__pWebReader != null)
561         {
562                 __pWebReader->LoadData(L"",buf,L"text/html");
563                 AppLogDebug("LoadData result %s",GetErrorMessage(GetLastResult()));
564         }
565         else
566         {
567                 AppLogDebug("cannot LoadData __pWebReader is null");
568         }
569
570
571 }
572
573 void
574 ArticleReaderForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
575 {
576         AppLog("ArticleReaderForm::OnSceneDeactivated entered");
577 }
578
579 void
580 ArticleReaderForm::OnTextFound(int totalCount, int currentOrdinal)
581 {
582         AppLog("ArticleReaderForm::OnTextFound totalCount %d",totalCount);
583         AppLog("ArticleReaderForm::OnTextFound currentOrdinal %d",currentOrdinal);
584
585         if(totalCount == -1 || totalCount == 0)
586         {
587                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
588                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
589         }
590         else if(totalCount > 100)
591         {
592                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
593                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
594         }
595         else
596         {
597                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
598                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
599         }
600
601         if (totalCount <= 0)
602         {
603                 __pFindWordNext->SetEnabled(false);
604         }
605         else
606         {
607                 __pFindWordNext->SetEnabled(true);
608         }
609
610         String countStr = L"";
611         countStr.Append(currentOrdinal);
612         countStr.Append(L"/");
613         countStr.Append(totalCount);
614         __pFindWordCountLabel->SetText(countStr);
615         __pFindWordCountLabel->Invalidate(false);
616
617         //FindNextWord(true);
618         //Update the controls
619         __pFindWordNext->Invalidate(false);
620 }
621
622 void
623 ArticleReaderForm::OnWebPageBlockSelected(Tizen::Web::Controls::Web& source, Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint)
624 {
625         AppLog("ArticleReaderForm::OnWebPageBlockSelected");
626         if (__pHitElementResult != null)
627         {
628                 delete __pHitElementResult;
629                 __pHitElementResult = null;
630         }
631
632         if (__pWebReader != null)
633         {
634                 AppLog("ArticleReaderForm::OnWebPageBlockSelected web not null");
635                 __pHitElementResult = __pWebReader->GetElementByPointN(startPoint);
636                 if(GetLastResult() == E_INVALID_ARG)
637                 {
638                         __pHitElementResult = __pWebReader->GetElementByPointN(endPoint);
639                 }
640         }
641
642         if (__pHitElementResult == null)
643         {
644                 return;
645         }
646
647         if (__pHitElementResult->HasImage() != true)
648         {
649                 String tagName = __pHitElementResult->GetTagName();
650                 String type = __pHitElementResult->GetAttributeValue("type");
651
652
653                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0))
654                 {
655
656                 }
657                 else
658                 {
659                         AppLog("ArticleReaderForm::OnWebPageBlockSelected no paste option");
660
661                         if(__pHitElementResult->GetUrl().GetLength() > 0)
662                         {
663                         }
664                         InitSelectTextContextMenu(endPoint);
665                         __pSelectionMenu->SetShowState(true);
666                         __pSelectionMenu->Show();
667                         __pSelectionMenu->Invalidate(true);
668                 }
669
670                 AppLog("ArticleReaderForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
671                 AppLog("ArticleReaderForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
672         }
673
674 }
675
676 void
677 ArticleReaderForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
678 {
679         AppLog("ArticleReaderForm::OnOrientationChanged entered");
680         if(__pFindWordControl)
681         {
682                 if (__pFindWordBgLabel != null)
683                 {
684                         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
685                         if (pBitmap != null)
686                         {
687                                 __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
688                                 delete pBitmap;
689                         }
690                 }
691
692                 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
693         }
694         RelayoutControls();
695 }
696
697
698 void
699 ArticleReaderForm::OnTextValueChanged (const Tizen::Ui::Control &source)
700 {
701         if (__pFindWordEditField != null)
702         {
703                 __pFindWordNext->SetEnabled(false);
704                 __pFindWordPrev->SetEnabled(false);
705                 __pFindWordNext->Invalidate(true);
706                 __pFindWordPrev->Invalidate(true);
707                 __pFindWordCountLabel->SetText(L"0/0");
708                 __pFindWordCountLabel->Invalidate(true);
709         }
710         if (__pFindWordEditField->GetText().GetLength() > 0)
711         {
712                 StartWordSearch();
713         }
714         else
715         {
716                 __pFindWordPrev->SetEnabled(false);
717                 __pWebReader->SearchText(L"aaaaaaaabbbbbbbccccccc");
718         }
719         __randomValue = true;
720 //      else
721 //      {
722 ////            currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
723 //              StartWordSearch();
724 ////            currentSearchStr = L"";
725 //              AppLogDebug("Enter something");
726 //      }
727 }
728
729 result
730 ArticleReaderForm::InitSelectTextContextMenu(Tizen::Graphics::Point p)
731 {
732         result r = E_SUCCESS;
733         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
734
735         AppLog("ArticleReaderForm::InitSelectTextContextMenu clicked on text");
736         if (__pSelectionMenu != null)
737         {
738                 delete __pSelectionMenu;
739                 __pSelectionMenu = null;
740         }
741
742         if(p.y < 150)
743         {
744                 p.y = p.y + 50;
745                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
746         }
747         else
748         {
749                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
750         }
751         __pSelectionMenu = new (std::nothrow) ContextMenu();
752         r = __pSelectionMenu->Construct(p, CONTEXT_MENU_STYLE_GRID, direction);
753         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
754
755         r = __pSelectionMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_COPY"),IDA_COPY_TEXT_CLICKED);
756         r = __pSelectionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"),IDA_FIND_TEXT_CLICKED);
757         r = __pSelectionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_TEXT_CLICKED);
758
759         __pSelectionMenu->SetMaxVisibleItemsCount(3);
760         __pSelectionMenu->AddActionEventListener(*this);
761         SetControlAlwaysOnTop(*__pSelectionMenu, true);
762
763         CATCH: return r;
764
765 }
766
767 result
768 ArticleReaderForm::InitFindWordPanel(void)
769 {
770         result r = E_SUCCESS;
771         Bitmap *pIconBitmap = null;
772
773         if (__pFindWordControl != null)
774         {
775                 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
776                 __pFindWordControl->SetShowState(true);
777                 __pFindWordEditField->SetText(__pWebReader->GetTextFromBlock());
778
779
780                 __pFindWordEditField->SetFocus();
781
782                 if (__pFindWordEditField->GetText().GetLength() > 0)
783                 {
784                         StartWordSearch();
785                 }
786                 __pFindWordEditField->Invalidate(false);
787                 return r;
788         }
789
790         __pFindWordControl = new (std::nothrow) Panel();
791         r = __pFindWordControl->Construct(L"IDL_FIND_ON_PAGE");
792         if (IsFailed(r))
793         {
794                 AppLogException("There is some problem in the xml file. Please check.");
795                 return E_FAILURE;
796         }
797         AddControl(__pFindWordControl);
798         __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
799         SetControlAlwaysOnTop(*__pFindWordControl,true);
800         __pFindWordControl->SetShowState(true);
801         __pFindWordControl->Invalidate(false);
802
803         __pFindWordBgLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_LABEL1", true));
804         if (__pFindWordBgLabel != null)
805         {
806                 Panel* pPanel1 = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL1", true));
807                 Rectangle pRect = pPanel1->GetBounds();
808                 pRect.x = pRect.y = 0;
809                 __pFindWordBgLabel->SetBounds(pRect);
810                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_search_input_field_bg.9.png", __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
811                 if (pBitmap != null)
812                 {
813                         AppLogDebug("InitFindWordPanel: Coming here");
814                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
815                         delete pBitmap;
816                 }
817                 else
818                 {
819                         AppLogDebug("InitFindWordPanel: shouldn't Come here");
820                 }
821         }
822
823         Button* pfindWordCancel = null;
824         pfindWordCancel = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CANCEL", true));
825         if (pfindWordCancel == null)
826         {
827                 AppLogException("There is some problem in the xml file. Please check.");
828                 return E_FAILURE;
829         }
830         pfindWordCancel->SetActionId(IDA_FINDWORD_CANCEL_CLICKED);
831         pfindWordCancel->AddActionEventListener(*this);
832
833         __pFindWordClear = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CLEAR", true));
834         if (__pFindWordClear == null)
835         {
836                 AppLogException("There is some problem in the xml file. Please check.");
837                 return E_FAILURE;
838         }
839
840         __pFindWordClear->SetActionId(IDA_FINDWORD_CLEAR_CLICKED);
841         __pFindWordClear->AddActionEventListener(*this);
842
843         __pFindWordNext = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_NEXT", true));
844         if (__pFindWordNext == null)
845         {
846                 AppLogException("There is some problem in the xml file. Please check.");
847                 return E_FAILURE;
848         }
849
850         __pFindWordNext->SetActionId(IDA_FINDWORD_NEXT_CLICKED);
851         __pFindWordNext->AddActionEventListener(*this);
852
853         __pFindWordPrev = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_PREV", true));
854         if (__pFindWordPrev == null)
855         {
856                 AppLogException("There is some problem in the xml file. Please check.");
857                 return E_FAILURE;
858         }
859
860         __pFindWordPrev->SetActionId(IDA_FINDWORD_PREV_CLICKED);
861         __pFindWordPrev->AddActionEventListener(*this);
862
863         __pFindWordNext->SetEnabled(false);
864         __pFindWordPrev->SetEnabled(false);
865
866         __pFindWordCountLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_FIND_COUNT_LABEL", true));
867         if (__pFindWordCountLabel == null)
868         {
869                 AppLogException("There is some problem in the xml file. Please check.");
870                 return E_FAILURE;
871         }
872
873         __pFindWordEditField = static_cast<EditField*>(__pFindWordControl->GetControl(L"IDC_FIND_WORD_EDITFIELD", true));
874         if (__pFindWordEditField == null)
875         {
876                 AppLogException("There is some problem in the xml file. Please check.");
877                 return E_FAILURE;
878         }
879         __pFindWordEditField->SetText(__pWebReader->GetTextFromBlock());
880         __pFindWordEditField->AddTextEventListener(*this);
881         __pFindWordEditField->AddKeypadEventListener(*this);
882         __pFindWordEditField->SetOverlayKeypadCommandButtonVisible(false);
883
884         __pFindWordEditField->SetFocus();
885 //      __pFindWordEditField->ShowKeypad();
886         if (__pFindWordEditField->GetText().GetLength() > 0)
887         {
888                 StartWordSearch();
889         }
890         return r;
891 }
892
893 void
894 ArticleReaderForm::StartWordSearch()
895 {
896         __pFindWordPrev->SetEnabled(false);
897         __pWebReader->SearchTextAllAsync(__pFindWordEditField->GetText(), false);
898
899 }
900
901 void
902 ArticleReaderForm::RelayoutControls()
903 {
904         if( __pFindWordControl && __pFindWordControl->GetShowState() == true)
905         {
906                 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
907                 if(__pFooterPanel && __pFooterPanel->GetShowState() == true && __pWebReader)
908                         __pWebReader->SetBounds(0,__pFindWordControl->GetHeight(),GetClientAreaBounds().width, GetClientAreaBounds().height - __pFooterPanel->GetHeight() - __pFindWordControl->GetHeight());
909                 else if(__pWebReader)
910                         __pWebReader->SetBounds(0,__pFindWordControl->GetHeight(),GetClientAreaBounds().width, GetClientAreaBounds().height - __pFindWordControl->GetHeight());
911         }
912         else
913         {
914                 if(__pFooterPanel && __pFooterPanel->GetShowState() == true && __pWebReader)
915                         __pWebReader->SetBounds(0,0,GetClientAreaBounds().width, GetClientAreaBounds().height - __pFooterPanel->GetHeight());
916                 else if(__pWebReader)
917                         __pWebReader->SetBounds(0,0,GetClientAreaBounds().width, GetClientAreaBounds().height);
918
919         }
920 }
921
922
923 void
924 ArticleReaderForm::FindNextWord(bool next)
925 {
926         String currentSearchStr = __pFindWordEditField->GetText();
927         int currentWordIndex = 0;
928         String curWordIndexStr = L"";
929         int maxOccurances = 0;
930         String maxOccurancesStr = L"";
931         int index = -1;
932         String countStr = __pFindWordCountLabel->GetText();
933         countStr.IndexOf(L"/",0,index);
934         countStr.SubString(0,index,curWordIndexStr);
935         countStr.SubString(index+1,maxOccurancesStr);
936         Integer::Parse(curWordIndexStr,currentWordIndex);
937         Integer::Parse(maxOccurancesStr,maxOccurances);
938         if (next == true)
939         {
940                 if (__pWebReader->SearchText(currentSearchStr, true) == true)
941                 {
942                         if(currentWordIndex < maxOccurances)
943                         {
944                                 currentWordIndex++;
945                         }
946                         if(__randomValue == true)
947                         {
948                                 __randomValue = false;
949                                 __pWebReader->SearchText(currentSearchStr, true);
950                         }
951                 }
952         }
953         else
954         {
955                 if (__pWebReader->SearchText(currentSearchStr, false) == true)
956                 {
957                         if(currentWordIndex > 1)
958                         {
959                                 currentWordIndex--;
960                         }
961                 }
962         }
963
964         countStr.Clear();
965         countStr.Append(currentWordIndex);
966         countStr.Append(L"/");
967         countStr.Append(maxOccurances);
968         __pFindWordCountLabel->SetText(countStr);
969         //      __pFindWordCountLabel->SetShowState(true);
970         __pFindWordCountLabel->Invalidate(false);
971         if (currentWordIndex >= maxOccurances)
972         {
973                 __pFindWordNext->SetEnabled(false);
974         }
975         else
976         {
977                 __pFindWordNext->SetEnabled(true);
978         }
979         if (currentWordIndex <= 1)
980         {
981                 __pFindWordPrev->SetEnabled(false);
982         }
983         else
984         {
985                 __pFindWordPrev->SetEnabled(true);
986         }
987         __pFindWordPrev->Invalidate(false);
988         __pFindWordNext->Invalidate(false);
989         __pFindWordCountLabel->Invalidate(false);
990         __pFindWordControl->Invalidate(true);
991 }