2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file CommonUtils.cpp
19 * @brief commonly used functions
24 #include <FGraphics.h>
25 #include "PhnAppUtility.h"
26 #include "PhnCommonUtils.h"
28 using namespace Tizen::App;
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Base::Collection;
34 const int ID_NAME_STRING = 100;
35 const int ID_NUMBER_STRING = 101;
36 const int ID_TIME_STRING = 102;
37 const int ID_CONTACT_BITMAP = 103;
38 const int ID_CALLTYPE_BITMAP = 104;
39 const int ID_NAME_STRING_COUNTER = 105;
40 const int ID_LOGCALL_BITMAP = 50;
41 const int ID_NAME_STRING_FONT_SIZE = 44;
42 static const int X_LIST_DISPNAME = 26;
43 static const int Y_LIST_DISPNAME = 22;
44 static const int X_LIST_NUMBER = 26;
45 static const int Y_LIST_NUMBER = 76;//22+54;
47 const int X_TEXT_LINE1_ITEM = 16;
48 const int Y_TEXT_LINE1_ITEM = 10;
49 const int H_TEXT_LINE1_ITEM = 60;
50 const int W_TEXT_LINE1_ITEM = 560;
51 const int W_TEXT_LINE1_ITEM_RIGHT_MARGIN = 170;
52 const int W_TEXT_LINE1_ITEM_COUNTER = 80;
54 const int X_TEXT_LINE2_ITEM = 64;
55 const int Y_TEXT_LINE2_ITEM = 70;
56 const int H_TEXT_LINE2_ITEM = 48;
57 const int W_TEXT_LINE2_ITEM = 256;
58 const int W_TEXT_LINE2_ITEM_RIGHT_MARGIN = 230;
59 const int W_TEXT_LINE2_ITEM_RIGHT_MARGIN_DELETE = 96;
61 const int X_TEXT_TIME_ITEM = 440;
62 const int Y_TEXT_TIME_ITEM = 70;
63 const int H_TEXT_TIME_ITEM = 48;
64 const int W_TEXT_TIME_ITEM = 256;
65 const int X_TEXT_TIME_ITEM_RIGHT_MARGIN = 280;
67 const int X_CONTACT_BITMAP_ITEM = 592;
68 const int Y_CONTACT_BITMAP_ITEM = 0;
69 const int H_CONTACT_BITMAP_ITEM = 177;
70 const int W_CONTACT_BITMAP_ITEM = 177;
72 const int X_CALLTYPE_BITMAP_ITEM = 16;
73 const int Y_CALLTYPE_BITMAP_ITEM = 70 + 8;
74 const int H_CALLTYPE_BITMAP_ITEM = 32;
75 const int W_CALLTYPE_BITMAP_ITEM = 32;
77 //New Keypad Button Images for numbers
78 const int X_DIALER_BTN_IMG = 0;
79 const int Y_DIALER_BTN_IMG = 10;
81 //Call Patch Coordinates
82 const int X_CALL_PATCH = 36;
83 const int Y_CALL_PATCH = 18;
84 const int W_CALL_PATCH = 444;
85 const int H_CALL_PATCH = 104;
87 //Clear Button Patch Coordinates
88 const int X_CLEAR_PATCH = 0;
89 const int Y_CLEAR_PATCH = 18;
90 const int W_CLEAR_PATCH = 180;
91 const int H_CLEAR_PATCH = 104;
93 const int X_LOGCALL_BITMAP_ITEM = 660;
94 const int Y_LOGCALL_BITMAP_ITEM = 10;
95 const int W_LOGCALL_BITMAP_ITEM = 38;
96 const int H_LOGCALL_BITMAP_ITEM = 38;
97 const int X_LOGCALL_BITMAP_RIGHT_MARGIN = 60;
99 const int X_DIALER_BTN_TXT = 13;
100 const int W_DIALER_BTN_NUM_TXT = 77;
101 const int W_DIALER_BTN_ALPHA_TXT = 121;
103 const int W_ENRICHED_TEXT = 190;
104 const int X_ENRICHED_TEXT = 143;
105 const int IDI_RIGHT_MARGIN_USE_CONTACT_BTN = 160;
106 const int H_USE_CONTACT_BTN = 60;
109 DialUtil::GetTextFontN(int textFontStyle)
111 Font* font = new (std::nothrow) Font();
113 switch (textFontStyle)
115 case FONT_CALLING_TEXT:
117 font->Construct(FONT_STYLE_PLAIN, 94);
121 case FONT_SEARCH_TEXT:
123 font->Construct(FONT_STYLE_PLAIN, 36);
127 case FONT_KEYPAD_NUMBER:
129 font->Construct(FONT_STYLE_PLAIN, 116);
133 case FONT_KEYPAD_TEXT:
135 font->Construct(FONT_STYLE_PLAIN, 28);
141 font->Construct(FONT_STYLE_PLAIN, 28);
145 case FONT_KEYPAD_PLUS:
147 font->Construct(FONT_STYLE_PLAIN, 40);
151 case FONT_KEYPAD_CANCEL:
153 font->Construct(FONT_STYLE_PLAIN, 34);
157 case FONT_SUGGESTION_NAME:
159 font->Construct(FONT_STYLE_PLAIN, 44);
163 case FONT_SUGGESTION_MOBILE:
165 font->Construct(FONT_STYLE_PLAIN, 35);
169 case FONT_SUGGESTION_NUMBER:
171 font->Construct(FONT_STYLE_PLAIN, 32);
175 case FONT_SUGGESTION_LIST_NUMBER:
177 font->Construct(FONT_STYLE_PLAIN, 40);
180 case FONT_EXPAND_BUTTON_TEXT:
182 font->Construct(FONT_STYLE_PLAIN, 30);
185 case FONT_SPEEDDIAL_BTN_NUMBER:
187 font->Construct(FONT_STYLE_BOLD, 86);
195 DialUtil::GetTextColorN(int textColor, int buttonStatus)
197 Color* color = new (std::nothrow) Color();
199 if (buttonStatus == BUTTON_STATUS_PRESSED)
201 //color->SetColorComponents(249, 249, 249);
202 color->SetColorComponents(145, 135, 114);
208 case FONT_CALLING_TEXT:
210 color->SetColorComponents(0, 0, 0);
214 case FONT_SEARCH_TEXT:
216 color->SetColorComponents(156, 159, 162);
220 case FONT_SPEEDDIAL_BTN_NUMBER:
221 case FONT_KEYPAD_NUMBER:
223 color->SetColorComponents(255, 255, 255);
227 case FONT_KEYPAD_TEXT:
229 case FONT_KEYPAD_PLUS:
231 color->SetColorComponents(145, 135, 114);
235 case FONT_KEYPAD_CANCEL:
237 color->SetColorComponents(255, 255, 255);
241 case FONT_SUGGESTION_NAME:
243 color->SetColorComponents(0, 0, 0);
247 case FONT_SUGGESTION_MOBILE:
249 color->SetColorComponents(153, 153, 153);
253 case FONT_HIGHLIGHT_SEARCH_KEYWORD:
255 color->SetColorComponents(59, 115, 182);
258 case FONT_SUGGESTION_NUMBER:
260 color->SetColorComponents(153, 153, 153);
264 case FONT_SUGGESTION_LIST_NUMBER:
266 color->SetColorComponents(50, 50, 50);
269 case FONT_EXPAND_BUTTON_TEXT:
271 color->SetColorComponents(50, 50, 50);
279 DialUtil::IsNumericString(Tizen::Base::String& keyWord)
281 bool isDigit = false;
282 String digitStr(L"");
283 if(keyWord.SubString(0,1,digitStr) == E_SUCCESS)
286 if(Integer::Parse(digitStr,digit) == E_SUCCESS)
294 DialUtil::DrawBitmapToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
296 AppResource* pAppResource = AppResource::GetInstance();
297 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
300 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
306 DialUtil::DrawClear9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
308 AppResource* pAppResource = AppResource::GetInstance();
309 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
310 if (pBitmap->IsNinePatchedBitmap())
312 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH,W_CLEAR_PATCH,H_CLEAR_PATCH), *pBitmap);
314 pCanvas.DrawBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH, W_CLEAR_PATCH, H_CLEAR_PATCH), *pBitmap);
320 DialUtil::DrawCall9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
322 AppResource* pAppResource = AppResource::GetInstance();
323 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
324 if (pBitmap->IsNinePatchedBitmap())
326 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH,W_CALL_PATCH,H_CALL_PATCH), *pBitmap);
328 pCanvas.DrawBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH, W_CALL_PATCH, H_CALL_PATCH), *pBitmap);
334 DialUtil::Draw9PatchToCanvas(Canvas& pCanvas, const String& bgImg)
336 AppResource* pAppResource = AppResource::GetInstance();
337 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
340 if (pBitmap->IsNinePatchedBitmap())
342 pCanvas.DrawNinePatchedBitmap(pCanvas.GetBounds(), *pBitmap);
346 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
355 DialUtil::DrawKeypadImageToCanvas(const Tizen::Base::String& image, Tizen::Graphics::Dimension imageDimention, Tizen::Graphics::Canvas& pCanvas, int pos)
357 //create and scale bitmap
358 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
359 //Find position to draw bitmap
360 Point bitmapPos(0, 0);
364 case POSITION_TOP_CENTER:
366 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2,Y_DIALER_BTN_IMG);
369 case POSITION_BOTTOM_CENTER:
371 //bitmapPos.SetPosition(X_DIALER_BTN_IMG,Y_DIALER_BTN_IMG);
372 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, 20 + pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
377 pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
389 DialUtil::DrawImageToCanvas(const String& image, Dimension imageDimention, Canvas& pCanvas, int pos)
391 //create and scale bitmap
392 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
394 //Find position to draw bitmap
395 Point bitmapPos(0, 0);
400 bitmapPos.SetPosition(X_DIALER_BTN_TXT + (W_DIALER_BTN_NUM_TXT - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
406 bitmapPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((W_DIALER_BTN_ALPHA_TXT - pBitmap->GetWidth()) / 2), (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
410 case POSITION_CENTER:
412 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
416 case POSITION_BOTTOM_CENTER:
418 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
424 pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
432 DialUtil::DrawKeypadTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
434 AppLogDebug("ENTER");
435 if (buttonText == null)
441 Font* font = GetTextFontN(textFontStyle);
444 Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
446 //create text element
447 TextElement* pTextElement = new (std::nothrow) TextElement();
448 pTextElement->Construct(buttonText);
449 pTextElement->SetTextColor(*textColor);
450 pTextElement->SetFont(*font);
453 //get dimensions of the text
454 FloatDimension textDimension;
455 font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
456 if(textFontStyle != FONT_KEYPAD_NUMBER)
458 textDimension.height += font->GetDescender();
461 //create enriched text
462 EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
463 pEnrichedText->Construct(textDimension);
464 pEnrichedText->Add(*pTextElement);
466 //set the position of the text in canvas
470 case POSITION_BOTTOM_CENTER:
472 textPos.SetPosition(((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2),
473 20 + pCanvas.GetBounds().height / 2
474 + ((pCanvas.GetBounds().height / 2
475 - pEnrichedText->GetHeight()) / 2));
480 //Draw EnrichedText to canvas
481 pCanvas.DrawText(textPos, *pEnrichedText);
484 pEnrichedText->RemoveAll(true);
485 delete pEnrichedText;
493 DialUtil::DrawTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
495 if (buttonText == null)
501 Font* font = GetTextFontN(textFontStyle);
504 Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
506 //create text element
507 TextElement* pTextElement = new (std::nothrow) TextElement();
508 pTextElement->Construct(buttonText);
509 pTextElement->SetTextColor(*textColor);
510 pTextElement->SetFont(*font);
513 //get dimensions of the text
514 FloatDimension textDimension;
515 font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
516 if(textFontStyle != FONT_KEYPAD_NUMBER)
518 textDimension.height += font->GetDescender();
521 //create enriched text
522 EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
523 pEnrichedText->Construct(textDimension);
524 pEnrichedText->Add(*pTextElement);
526 //set the position of the text in canvas
532 //Margin 13, rectangle for left text (13,0,77, height of canvas), center aligned
533 textPos.SetPosition(X_DIALER_BTN_TXT + ((W_DIALER_BTN_NUM_TXT - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
539 //rectangle for right text (13+77,0, 121, height of canvas), center aligned
540 textPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((121 - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
544 case POSITION_CENTER:
546 //rectangle for image : entire canvas, center aligned
547 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
551 case POSITION_TOP_LEFT:
553 textPos.SetPosition(10, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
557 case POSITION_TOP_CENTER:
559 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
563 case POSITION_BOTTOM_LEFT:
565 textPos.SetPosition(10, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
569 case POSITION_BOTTOM_CENTER:
571 int width = pEnrichedText->GetWidth();
572 if(width > W_ENRICHED_TEXT)
574 textPos.SetPosition(X_ENRICHED_TEXT, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
578 textPos.SetPosition(10 + ((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2), pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
583 case POSITION_SUGGESTION_NAME:
585 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
588 case POSITION_SUGGESTION_NUMBER:
590 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
596 //Draw EnrichedText to canvas
597 pCanvas.DrawText(textPos, *pEnrichedText);
600 pEnrichedText->RemoveAll(true);
601 delete pEnrichedText;
609 DialUtil::DrawCanvasToButton(Canvas* pCanvasNormal, Canvas* pCanvasPressed, Button* pButton)
611 Bitmap* pNormalBgBmp = new (std::nothrow) Bitmap();
612 pNormalBgBmp->Construct(*pCanvasNormal, pCanvasNormal->GetBounds());
614 pButton->SetNormalBackgroundBitmap(*pNormalBgBmp);
616 if (pCanvasPressed != null)
618 Bitmap* pPressedBgBmp = new (std::nothrow) Bitmap();
619 pPressedBgBmp->Construct(*pCanvasPressed, pCanvasPressed->GetBounds());
620 pButton->SetPressedBackgroundBitmap(*pPressedBgBmp);
621 delete pPressedBgBmp;
622 pPressedBgBmp = null;
626 pButton->SetPressedBackgroundBitmap(*pNormalBgBmp);
629 pButton->SetDisabledBitmap(Point(0, 0), *pNormalBgBmp);
630 pButton->Invalidate(true);
638 DialUtil::ConvertDialedNumberToString(int dialNumber)
714 DialUtil::FetchPossibleNamesListN(const String& prevSearchStr, int nextDigit)
716 //Fetch matching names for mapping char for digit, e.g. 2->ABC, 3->DEF.
717 ArrayList* pNamesList = new (std::nothrow) ArrayList(SingleObjectDeleter);
718 pNamesList->Construct(8);
720 if(nextDigit >=2 && nextDigit <= 9)
726 pNamesList->Add((new String(prevSearchStr+L"a")));
727 pNamesList->Add((new String(prevSearchStr+L"b")));
728 pNamesList->Add((new String(prevSearchStr+L"c")));
729 pNamesList->Add((new String(prevSearchStr+L"A")));
730 pNamesList->Add((new String(prevSearchStr+L"B")));
731 pNamesList->Add((new String(prevSearchStr+L"C")));
737 pNamesList->Add((new String(prevSearchStr+L"d")));
738 pNamesList->Add((new String(prevSearchStr+L"e")));
739 pNamesList->Add((new String(prevSearchStr+L"f")));
740 pNamesList->Add((new String(prevSearchStr+L"D")));
741 pNamesList->Add((new String(prevSearchStr+L"E")));
742 pNamesList->Add((new String(prevSearchStr+L"F")));
748 pNamesList->Add((new String(prevSearchStr+L"g")));
749 pNamesList->Add((new String(prevSearchStr+L"h")));
750 pNamesList->Add((new String(prevSearchStr+L"i")));
751 pNamesList->Add((new String(prevSearchStr+L"G")));
752 pNamesList->Add((new String(prevSearchStr+L"H")));
753 pNamesList->Add((new String(prevSearchStr+L"I")));
759 pNamesList->Add((new String(prevSearchStr+L"j")));
760 pNamesList->Add((new String(prevSearchStr+L"k")));
761 pNamesList->Add((new String(prevSearchStr+L"l")));
762 pNamesList->Add((new String(prevSearchStr+L"J")));
763 pNamesList->Add((new String(prevSearchStr+L"K")));
764 pNamesList->Add((new String(prevSearchStr+L"L")));
770 pNamesList->Add((new String(prevSearchStr+L"m")));
771 pNamesList->Add((new String(prevSearchStr+L"n")));
772 pNamesList->Add((new String(prevSearchStr+L"o")));
773 pNamesList->Add((new String(prevSearchStr+L"M")));
774 pNamesList->Add((new String(prevSearchStr+L"N")));
775 pNamesList->Add((new String(prevSearchStr+L"O")));
781 pNamesList->Add((new String(prevSearchStr+L"p")));
782 pNamesList->Add((new String(prevSearchStr+L"q")));
783 pNamesList->Add((new String(prevSearchStr+L"r")));
784 pNamesList->Add((new String(prevSearchStr+L"s")));
785 pNamesList->Add((new String(prevSearchStr+L"P")));
786 pNamesList->Add((new String(prevSearchStr+L"Q")));
787 pNamesList->Add((new String(prevSearchStr+L"R")));
788 pNamesList->Add((new String(prevSearchStr+L"S")));
794 pNamesList->Add((new String(prevSearchStr+L"t")));
795 pNamesList->Add((new String(prevSearchStr+L"u")));
796 pNamesList->Add((new String(prevSearchStr+L"v")));
797 pNamesList->Add((new String(prevSearchStr+L"T")));
798 pNamesList->Add((new String(prevSearchStr+L"U")));
799 pNamesList->Add((new String(prevSearchStr+L"V")));
805 pNamesList->Add((new String(prevSearchStr+L"w")));
806 pNamesList->Add((new String(prevSearchStr+L"x")));
807 pNamesList->Add((new String(prevSearchStr+L"y")));
808 pNamesList->Add((new String(prevSearchStr+L"z")));
809 pNamesList->Add((new String(prevSearchStr+L"W")));
810 pNamesList->Add((new String(prevSearchStr+L"X")));
811 pNamesList->Add((new String(prevSearchStr+L"Y")));
812 pNamesList->Add((new String(prevSearchStr+L"Z")));
822 DialUtil::ConvertNameToNumericKeys(String& subContactName, String& possibleKeysTyped)
824 for(int charPos=0;charPos < subContactName.GetLength();charPos++)
827 subContactName.GetCharAt(charPos,nextChar);
833 possibleKeysTyped.Append(2);
839 possibleKeysTyped.Append(3);
845 possibleKeysTyped.Append(4);
851 possibleKeysTyped.Append(5);
857 possibleKeysTyped.Append(6);
864 possibleKeysTyped.Append(7);
870 possibleKeysTyped.Append(8);
877 possibleKeysTyped.Append(9);
887 DialUtil::ConstructEnrichedTextN(String& text, String& matchedKeyword, int textFontStyle, Dimension txtDimension)
890 Font* fontName = DialUtil::GetTextFontN(textFontStyle);
892 Color* textColor = DialUtil::GetTextColorN(textFontStyle, BUTTON_STATUS_NORMAL);
893 //highlighted text Color
894 Color* highlightedTxtColor = DialUtil::GetTextColorN(FONT_HIGHLIGHT_SEARCH_KEYWORD, BUTTON_STATUS_NORMAL);
896 EnrichedText* pEnrichedName = new (std::nothrow) EnrichedText();
897 pEnrichedName->Construct(txtDimension);
898 pEnrichedName->SetTextWrapStyle(TEXT_WRAP_NONE);
899 //Text is divided in 3 parts - pre-text, highlighted matchedKeyword, post-text.
901 String highlightTxt(L"");
903 if(matchedKeyword.IsEmpty() == false)
906 result r = text.IndexOf(matchedKeyword,0,searchIndex);
911 text.SubString(0,searchIndex,preTxt);
913 text.SubString(searchIndex, matchedKeyword.GetLength(),highlightTxt);
914 text.SubString((searchIndex + matchedKeyword.GetLength()),postTxt);
922 TextElement* pTextName = null;
923 if(preTxt.IsEmpty() == false)
925 //create text element
926 pTextName = new (std::nothrow) TextElement();
927 pTextName->Construct(preTxt);
928 pTextName->SetFont(*fontName);
929 pTextName->SetTextColor(*textColor);
930 //ownership of 'pTextName' transferred to 'pEnrichedName'
931 pEnrichedName->Add(*pTextName);
934 if(highlightTxt.IsEmpty() == false)
936 //create text element
937 pTextName = new (std::nothrow) TextElement();
938 pTextName->Construct(highlightTxt);
939 pTextName->SetFont(*fontName);
940 // Highlighted search text
941 pTextName->SetTextColor(*highlightedTxtColor);
942 pEnrichedName->Add(*pTextName);
945 if(postTxt.IsEmpty() == false)
947 //create text element
948 pTextName = new (std::nothrow) TextElement();
949 pTextName->Construct(postTxt);
950 pTextName->SetFont(*fontName);
951 pTextName->SetTextColor(*textColor);
952 pEnrichedName->Add(*pTextName);
957 delete highlightedTxtColor;
959 return pEnrichedName;
963 DialUtil::DrawTextAndHighlightedKeywordToCanvas(String& buttonText, String& matchedKeyword, int textFontStyle, Canvas& pCanvas, int pos)
965 if (buttonText == null)
970 //Convert to enriched text with highlighted keyword
971 Dimension txtDimension (pCanvas.GetBounds().width - IDI_RIGHT_MARGIN_USE_CONTACT_BTN, H_USE_CONTACT_BTN);
972 EnrichedText* pEnrichedText = ConstructEnrichedTextN(buttonText, matchedKeyword, textFontStyle, txtDimension);
974 //set the position of the text in canvas
978 case POSITION_SUGGESTION_NAME:
980 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
984 case POSITION_SUGGESTION_NUMBER:
986 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
991 //Draw EnrichedText to canvas
992 pCanvas.DrawText(textPos, *pEnrichedText);
994 pEnrichedText->RemoveAll(true);
995 delete pEnrichedText;