3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 /*@file: ArticleReaderForm.cpp
20 *@brief: This header file contains the definitions of the ArticleReaderForm class.
26 #include "IntArticleReaderForm.h"
27 #include "IntCommonLib.h"
28 #include "IntSceneRegister.h"
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;
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.#.png";
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;
58 ArticleReaderForm::ArticleReaderForm(void):
63 ,__pSmallFontBtn(null)
64 ,__pLargeFontBtn(null)
66 ,__pHitElementResult(null)
67 ,__pSelectionMenu(null)
69 ,__pFindWordBgLabel(null)
70 ,__pFindWordClear(null)
71 ,__pFindWordCountLabel(null)
72 ,__pFindWordControl(null)
73 ,__pFindWordEditField(null)
74 ,__pFindWordNext(null)
75 ,__pFindWordPrev(null)
80 ArticleReaderForm::~ArticleReaderForm(void)
82 // RemoveAllControls();
86 ArticleReaderForm::Initialize(void)
88 AppLog("ArticleReaderForm::Initialize entered");
89 Construct(L"IDL_ARTICLE_READER_FORM");
94 ArticleReaderForm::OnInitializing(void)
96 AppLog("ArticleReaderForm::OnInitializing entered");
100 SceneManager* pSceneManager = SceneManager::GetInstance();
101 if (pSceneManager == null)
105 pSceneManager->AddSceneEventListener(IDSCN_ARTICLE_READER, *this);
107 __pFooterPanel = static_cast<Panel*>(GetControl("IDC_PANEL1",true));
108 if(__pFooterPanel == null)
110 AppLog("GetControl failed for FooterPanel button");
114 __pWebReader = new (std::nothrow) Web();
115 __pWebReader->Construct(Rectangle(0,0, GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
117 settings.SetInputStyle(INPUT_STYLE_OVERLAY);
118 settings.SetFontSize(24/*SettingPresentationModel::GetInstance()->GetReaderFontSize()*/);
120 r = __pWebReader->SetSetting(settings);
121 AddControl(__pWebReader);
122 SetControlAlwaysAtBottom(*__pWebReader,true);
123 __pWebReader->LoadUrl("http://google.com");//temporary only for testing
125 AppLogDebug("Web setting add failed with %s", GetErrorMessage(r));
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)
133 AppLog("GetControl failed for more button");
136 __pMoreBtn->AddActionEventListener(*this);
137 __pMoreBtn->SetActionId(IDA_MORE_BUTTON);
140 __pBackBtn = static_cast<Button*>(GetControl("IDC_BACK_BUTTON",true));
141 if(__pBackBtn == null)
143 AppLog("GetControl failed for back button");
146 __pBackBtn->AddActionEventListener(*this);
147 __pBackBtn->SetActionId(IDA_BACK_BUTTON);
150 __pSmallFontBtn = static_cast<Button*>(GetControl("IDC_SMALL_FONT_BUTTON",true));
151 if(__pSmallFontBtn == null)
153 AppLog("GetControl failed for small font button");
156 __pSmallFontBtn->AddActionEventListener(*this);
157 __pSmallFontBtn->SetActionId(IDA_SMALL_FONT_BUTTON);
158 __pSmallFontBtn->SetEnabled(false);
161 __pLargeFontBtn = static_cast<Button*>(GetControl("IDC_LARGE_FONT_BUTTON",true));
162 if(__pLargeFontBtn == null)
164 AppLog("GetControl failed for large font button");
167 __pLargeFontBtn->AddActionEventListener(*this);
168 __pLargeFontBtn->SetActionId(IDA_LARGE_FONT_BUTTON);
170 AddOrientationEventListener(*this);
176 ArticleReaderForm::OnTerminating(void)
178 AppLog("ArticleReaderForm::OnTerminating entered");
179 result r = E_SUCCESS;
184 ArticleReaderForm::OnActionPerformed(const Control& source, int actionId)
186 AppLog("ArticleReaderForm::OnActionPerformed entered actionId %d",actionId);
188 SceneManager* pSceneManager = SceneManager::GetInstance();
189 result r = E_SUCCESS;
191 if (pSceneManager == null)
198 case IDA_MORE_BUTTON:
200 if(__pMoreMenu != null)
205 __pMoreMenu = new(std::nothrow) ContextMenu();
206 r = __pMoreMenu->Construct(Point(50,GetClientAreaBounds().height),CONTEXT_MENU_STYLE_LIST,CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
208 TryCatch(!IsFailed(r),,"Contextmenu creation failed with%s",GetErrorMessage(r));
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);
216 __pMoreMenu->Invalidate(true);
217 __pMoreMenu->AddActionEventListener(*this);
218 SetControlAlwaysOnTop(*__pMoreMenu, true);
222 case IDA_BACK_BUTTON:
224 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition());
227 case IDA_SMALL_FONT_BUTTON:
229 WebSetting setting = __pWebReader->GetSetting();
230 setting.SetFontSize(24);
232 __pWebReader->SetSetting(setting);
233 __pSmallFontBtn->SetEnabled(false);
234 __pSmallFontBtn->Invalidate(true);
236 __pLargeFontBtn->SetEnabled(true);
237 __pLargeFontBtn->Invalidate(true);
240 case IDA_LARGE_FONT_BUTTON:
242 WebSetting setting = __pWebReader->GetSetting();
243 setting.SetFontSize(32);
244 __pWebReader->SetSetting(setting);
246 __pLargeFontBtn->SetEnabled(false);
247 __pLargeFontBtn->Invalidate(true);
249 __pSmallFontBtn->SetEnabled(true);
250 __pSmallFontBtn->Invalidate(true);
254 case IDA_SAVE_CLICKED:
256 if(__pWebReader !=null)
258 r = __pWebReader->SavePageAsPdf(UiApp::GetInstance()->GetAppRootPath()+"//data//test.pdf");
259 AppLog("SavePageAsPdf result %s",GetErrorMessage(r));
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);
267 __modalMsgBoxResult = 0;
272 case IDA_SHARE_CLICKED:
279 __pPopUp = new(std::nothrow) SharePopup();
280 __pPopUp->Initialize();
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);
289 __pPopUp->SetShowState(true);
293 case IDA_PRINT_CLICKED:
295 r = __pWebReader->SavePageAsPdf(UiApp::GetInstance()->GetAppRootPath()+"//data//test.pdf");
296 AppLog("SavePageAsPdf result %s",GetErrorMessage(r));
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;
303 AppLog("TestPrint if (pAc) == true");
308 String fileType = L"service_print_files_type";
309 String typeVal = L"DOC";
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";
316 map.Add(&fileCount, &countVal);
317 map.Add(&fileFolder, &folderVal);
318 map.Add(&fileType, &typeVal);
320 String fileName = L"service_print_files_files_name";
322 ArrayList fileNameList;
323 fileNameList.Construct();
324 String file1 = L"test.pdf";
326 fileNameList.Add(&file1);
327 map.Add(&fileName, &fileNameList);
329 nResult = pAc->Start(NULL, NULL, &map, NULL);
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");
347 int __modalMsgBoxResult;
348 MessageBox* pMsgBox = new MessageBox();
349 pMsgBox->Construct("Not Supported","Not Supported",MSGBOX_STYLE_OK,3000);
350 pMsgBox->ShowAndWait(__modalMsgBoxResult);
353 __modalMsgBoxResult = 0;
357 case IDA_COPY_TEXT_CLICKED:
360 // Sets data to a clip board 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)
369 pClipboard->CopyItem(item);
373 case IDA_FIND_TEXT_CLICKED:
375 __randomValue = true;
378 // __pWebReader->SetBounds(0,__pFindWordControl->GetHeight(),GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight() - __pFindWordControl->GetHeight());
381 case IDA_SHARE_TEXT_CLICKED:
383 AppLogDebug("IDA_SHARE_TEXT_CLICKED");
389 __pPopUp = new(std::nothrow) SharePopup();
390 __pPopUp->Initialize();
391 if (__pHitElementResult != null)
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);
405 case IDA_FINDWORD_CANCEL_CLICKED:
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);
421 case IDA_FINDWORD_CLEAR_CLICKED:
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);
431 case IDA_FINDWORD_NEXT_CLICKED:
436 case IDA_FINDWORD_PREV_CLICKED:
450 ArticleReaderForm::OnKeypadOpened(Tizen::Ui::Control& source)
452 __pFooterPanel->SetShowState(false);
456 ArticleReaderForm::OnKeypadClosed(Tizen::Ui::Control& source)
458 __pFooterPanel->SetShowState(true);
463 ArticleReaderForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
465 AppLog("ArticleReaderForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
467 if (__pHitElementResult != null)
469 delete __pHitElementResult;
470 __pHitElementResult = null;
473 if (__pWebReader != null)
475 AppLog("ArticleReaderForm::OnTouchLongPressed web not null");
476 __pHitElementResult = __pWebReader->GetElementByPointN(currentPosition);
479 if (__pHitElementResult == null)
484 if (__pHitElementResult->HasImage() == true)
488 else if(__pHitElementResult->HasUrl() == true)
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");
499 result r =__pWebReader->SetBlockSelectionPosition(currentPosition);
500 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
503 // __inputEventToBeSupressed = true;
507 ArticleReaderForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
509 AppLog("ArticleReaderForm::OnSceneActivatedN entered");
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());
516 String loadData = L"<html>\
518 <meta name='viewport' content='width=device-width*0.73,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'>\
523 background-color: transparent;\
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>");
550 buf.Construct(loadData.GetLength());
551 AppLogDebug("data->GetLength %d",loadData.GetLength());
552 for (int z=0;z<loadData.GetLength();z++)
555 loadData.GetCharAt(z,b);
556 buf.SetByte((byte)b);
560 if (__pWebReader != null)
562 __pWebReader->LoadData(L"",buf,L"text/html");
563 AppLogDebug("LoadData result %s",GetErrorMessage(GetLastResult()));
567 AppLogDebug("cannot LoadData __pWebReader is null");
574 ArticleReaderForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
576 AppLog("ArticleReaderForm::OnSceneDeactivated entered");
580 ArticleReaderForm::OnTextFound(int totalCount, int currentOrdinal)
582 AppLog("ArticleReaderForm::OnTextFound totalCount %d",totalCount);
583 AppLog("ArticleReaderForm::OnTextFound currentOrdinal %d",currentOrdinal);
585 if(totalCount == -1 || totalCount == 0)
587 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
588 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
590 else if(totalCount > 100)
592 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
593 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
597 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
598 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
603 __pFindWordNext->SetEnabled(false);
607 __pFindWordNext->SetEnabled(true);
610 String countStr = L"";
611 countStr.Append(currentOrdinal);
612 countStr.Append(L"/");
613 countStr.Append(totalCount);
614 __pFindWordCountLabel->SetText(countStr);
615 __pFindWordCountLabel->Invalidate(false);
617 //FindNextWord(true);
618 //Update the controls
619 __pFindWordNext->Invalidate(false);
623 ArticleReaderForm::OnWebPageBlockSelected(Tizen::Web::Controls::Web& source, Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint)
625 AppLog("ArticleReaderForm::OnWebPageBlockSelected");
626 if (__pHitElementResult != null)
628 delete __pHitElementResult;
629 __pHitElementResult = null;
632 if (__pWebReader != null)
634 AppLog("ArticleReaderForm::OnWebPageBlockSelected web not null");
635 __pHitElementResult = __pWebReader->GetElementByPointN(startPoint);
636 if(GetLastResult() == E_INVALID_ARG)
638 __pHitElementResult = __pWebReader->GetElementByPointN(endPoint);
642 if (__pHitElementResult == null)
647 if (__pHitElementResult->HasImage() != true)
649 String tagName = __pHitElementResult->GetTagName();
650 String type = __pHitElementResult->GetAttributeValue("type");
653 if (((tagName.CompareTo(L"INPUT") == 0) || tagName.CompareTo(L"TEXTAREA") == 0))
659 AppLog("ArticleReaderForm::OnWebPageBlockSelected no paste option");
661 if(__pHitElementResult->GetUrl().GetLength() > 0)
664 InitSelectTextContextMenu(endPoint);
665 __pSelectionMenu->SetShowState(true);
666 __pSelectionMenu->Show();
667 __pSelectionMenu->Invalidate(true);
670 AppLog("ArticleReaderForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
671 AppLog("ArticleReaderForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
677 ArticleReaderForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
679 AppLog("ArticleReaderForm::OnOrientationChanged entered");
680 if(__pFindWordControl)
682 if (__pFindWordBgLabel != null)
684 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
687 __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
692 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
699 ArticleReaderForm::OnTextValueChanged (const Tizen::Ui::Control &source)
701 if (__pFindWordEditField != null)
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);
710 if (__pFindWordEditField &&__pFindWordEditField->GetText().GetLength() > 0)
716 __pFindWordPrev->SetEnabled(false);
717 __pWebReader->SearchText(L"aaaaaaaabbbbbbbccccccc");
719 __randomValue = true;
722 //// currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
723 // StartWordSearch();
724 //// currentSearchStr = L"";
725 // AppLogDebug("Enter something");
730 ArticleReaderForm::InitSelectTextContextMenu(Tizen::Graphics::Point p)
732 result r = E_SUCCESS;
733 ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
735 AppLog("ArticleReaderForm::InitSelectTextContextMenu clicked on text");
736 if (__pSelectionMenu != null)
738 delete __pSelectionMenu;
739 __pSelectionMenu = null;
745 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
749 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
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));
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);
759 __pSelectionMenu->SetMaxVisibleItemsCount(3);
760 __pSelectionMenu->AddActionEventListener(*this);
761 SetControlAlwaysOnTop(*__pSelectionMenu, true);
768 ArticleReaderForm::InitFindWordPanel(void)
770 result r = E_SUCCESS;
771 Bitmap *pIconBitmap = null;
773 if (__pFindWordControl != null)
775 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
776 __pFindWordControl->SetShowState(true);
777 __pFindWordEditField->SetText(__pWebReader->GetTextFromBlock());
780 __pFindWordEditField->SetFocus();
782 if (__pFindWordEditField->GetText().GetLength() > 0)
786 __pFindWordEditField->Invalidate(false);
790 __pFindWordControl = new (std::nothrow) Panel();
791 r = __pFindWordControl->Construct(L"IDL_FIND_ON_PAGE");
794 AppLogException("There is some problem in the xml file. Please check.");
797 AddControl(__pFindWordControl);
798 __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
799 SetControlAlwaysOnTop(*__pFindWordControl,true);
800 __pFindWordControl->SetShowState(true);
801 __pFindWordControl->Invalidate(false);
803 __pFindWordBgLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_LABEL1", true));
804 if (__pFindWordBgLabel != null)
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());
813 AppLogDebug("InitFindWordPanel: Coming here");
814 __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
819 AppLogDebug("InitFindWordPanel: shouldn't Come here");
823 Button* pfindWordCancel = null;
824 pfindWordCancel = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CANCEL", true));
825 if (pfindWordCancel == null)
827 AppLogException("There is some problem in the xml file. Please check.");
830 pfindWordCancel->SetActionId(IDA_FINDWORD_CANCEL_CLICKED);
831 pfindWordCancel->AddActionEventListener(*this);
833 __pFindWordClear = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CLEAR", true));
834 if (__pFindWordClear == null)
836 AppLogException("There is some problem in the xml file. Please check.");
840 __pFindWordClear->SetActionId(IDA_FINDWORD_CLEAR_CLICKED);
841 __pFindWordClear->AddActionEventListener(*this);
843 __pFindWordNext = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_NEXT", true));
844 if (__pFindWordNext == null)
846 AppLogException("There is some problem in the xml file. Please check.");
850 __pFindWordNext->SetActionId(IDA_FINDWORD_NEXT_CLICKED);
851 __pFindWordNext->AddActionEventListener(*this);
853 __pFindWordPrev = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_PREV", true));
854 if (__pFindWordPrev == null)
856 AppLogException("There is some problem in the xml file. Please check.");
860 __pFindWordPrev->SetActionId(IDA_FINDWORD_PREV_CLICKED);
861 __pFindWordPrev->AddActionEventListener(*this);
863 __pFindWordNext->SetEnabled(false);
864 __pFindWordPrev->SetEnabled(false);
866 __pFindWordCountLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_FIND_COUNT_LABEL", true));
867 if (__pFindWordCountLabel == null)
869 AppLogException("There is some problem in the xml file. Please check.");
873 __pFindWordEditField = static_cast<EditField*>(__pFindWordControl->GetControl(L"IDC_FIND_WORD_EDITFIELD", true));
874 if (__pFindWordEditField == null)
876 AppLogException("There is some problem in the xml file. Please check.");
879 __pFindWordEditField->SetText(__pWebReader->GetTextFromBlock());
880 __pFindWordEditField->AddTextEventListener(*this);
881 __pFindWordEditField->AddKeypadEventListener(*this);
882 __pFindWordEditField->SetOverlayKeypadCommandButtonVisible(false);
884 __pFindWordEditField->SetFocus();
885 // __pFindWordEditField->ShowKeypad();
886 if (__pFindWordEditField->GetText().GetLength() > 0)
894 ArticleReaderForm::StartWordSearch()
896 __pFindWordPrev->SetEnabled(false);
897 __pWebReader->SearchTextAllAsync(__pFindWordEditField->GetText(), false);
902 ArticleReaderForm::RelayoutControls()
904 if( __pFindWordControl && __pFindWordControl->GetShowState() == true)
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());
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);
924 ArticleReaderForm::FindNextWord(bool next)
926 String currentSearchStr = __pFindWordEditField->GetText();
927 int currentWordIndex = 0;
928 String curWordIndexStr = L"";
929 int maxOccurances = 0;
930 String maxOccurancesStr = L"";
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);
940 if (__pWebReader->SearchText(currentSearchStr, true) == true)
942 if(currentWordIndex < maxOccurances)
946 if(__randomValue == true)
948 __randomValue = false;
949 __pWebReader->SearchText(currentSearchStr, true);
955 if (__pWebReader->SearchText(currentSearchStr, false) == true)
957 if(currentWordIndex > 1)
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)
973 __pFindWordNext->SetEnabled(false);
977 __pFindWordNext->SetEnabled(true);
979 if (currentWordIndex <= 1)
981 __pFindWordPrev->SetEnabled(false);
985 __pFindWordPrev->SetEnabled(true);
987 __pFindWordPrev->Invalidate(false);
988 __pFindWordNext->Invalidate(false);
989 __pFindWordCountLabel->Invalidate(false);
990 __pFindWordControl->Invalidate(true);