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 = 220;
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);
298 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
302 DialUtil::DrawClear9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
304 AppResource* pAppResource = AppResource::GetInstance();
305 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
306 if (pBitmap->IsNinePatchedBitmap())
308 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH,W_CLEAR_PATCH,H_CLEAR_PATCH), *pBitmap);
310 pCanvas.DrawBitmap(Rectangle(X_CLEAR_PATCH,Y_CLEAR_PATCH, W_CLEAR_PATCH, H_CLEAR_PATCH), *pBitmap);
316 DialUtil::DrawCall9PatchToCanvas(Tizen::Graphics::Canvas& pCanvas, const Tizen::Base::String& bgImg)
318 AppResource* pAppResource = AppResource::GetInstance();
319 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
320 if (pBitmap->IsNinePatchedBitmap())
322 pCanvas.DrawNinePatchedBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH,W_CALL_PATCH,H_CALL_PATCH), *pBitmap);
324 pCanvas.DrawBitmap(Rectangle(X_CALL_PATCH,Y_CALL_PATCH, W_CALL_PATCH, H_CALL_PATCH), *pBitmap);
330 DialUtil::Draw9PatchToCanvas(Canvas& pCanvas, const String& bgImg)
332 AppResource* pAppResource = AppResource::GetInstance();
333 Bitmap* pBitmap = pAppResource->GetBitmapN(bgImg);
336 if (pBitmap->IsNinePatchedBitmap())
338 pCanvas.DrawNinePatchedBitmap(pCanvas.GetBounds(), *pBitmap);
342 pCanvas.DrawBitmap(pCanvas.GetBounds(),*pBitmap);
351 DialUtil::DrawKeypadImageToCanvas(const Tizen::Base::String& image, Tizen::Graphics::Dimension imageDimention, Tizen::Graphics::Canvas& pCanvas, int pos)
353 //create and scale bitmap
354 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
355 //Find position to draw bitmap
356 Point bitmapPos(0, 0);
360 case POSITION_TOP_CENTER:
362 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2,Y_DIALER_BTN_IMG);
365 case POSITION_BOTTOM_CENTER:
367 //bitmapPos.SetPosition(X_DIALER_BTN_IMG,Y_DIALER_BTN_IMG);
368 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, 20 + pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
373 pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
385 DialUtil::DrawImageToCanvas(const String& image, Dimension imageDimention, Canvas& pCanvas, int pos)
387 //create and scale bitmap
388 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(image, imageDimention.width, imageDimention.height);
390 //Find position to draw bitmap
391 Point bitmapPos(0, 0);
396 bitmapPos.SetPosition(X_DIALER_BTN_TXT + (W_DIALER_BTN_NUM_TXT - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
402 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);
406 case POSITION_CENTER:
408 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, (pCanvas.GetBounds().height - pBitmap->GetHeight()) / 2);
412 case POSITION_BOTTOM_CENTER:
414 bitmapPos.SetPosition((pCanvas.GetBounds().width - pBitmap->GetWidth()) / 2, pCanvas.GetBounds().height / 2 + (pCanvas.GetBounds().height / 2 - pBitmap->GetHeight()) / 2);
420 pCanvas.DrawBitmap(Rectangle(bitmapPos, Dimension(pBitmap->GetWidth(), pBitmap->GetHeight())), *pBitmap);
428 DialUtil::DrawKeypadTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
430 AppLogDebug("ENTER");
431 if (buttonText == null)
437 Font* font = GetTextFontN(textFontStyle);
440 Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
442 //create text element
443 TextElement* pTextElement = new (std::nothrow) TextElement();
444 pTextElement->Construct(buttonText);
445 pTextElement->SetTextColor(*textColor);
446 pTextElement->SetFont(*font);
449 //get dimensions of the text
450 FloatDimension textDimension;
451 font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
452 if(textFontStyle != FONT_KEYPAD_NUMBER)
454 textDimension.height += font->GetDescender();
457 //create enriched text
458 EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
459 pEnrichedText->Construct(textDimension);
460 pEnrichedText->Add(*pTextElement);
462 //set the position of the text in canvas
466 case POSITION_BOTTOM_CENTER:
468 int width = pEnrichedText->GetWidth();
469 textPos.SetPosition(((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2),
470 20 + pCanvas.GetBounds().height / 2
471 + ((pCanvas.GetBounds().height / 2
472 - pEnrichedText->GetHeight()) / 2));
477 //Draw EnrichedText to canvas
478 pCanvas.DrawText(textPos, *pEnrichedText);
481 pEnrichedText->RemoveAll(true);
482 delete pEnrichedText;
490 DialUtil::DrawTextToCanvas(const String& buttonText, int textFontStyle, Canvas& pCanvas, int pos, int buttonStatus)
492 if (buttonText == null)
498 Font* font = GetTextFontN(textFontStyle);
501 Color* textColor = GetTextColorN(textFontStyle, buttonStatus);
503 //create text element
504 TextElement* pTextElement = new (std::nothrow) TextElement();
505 pTextElement->Construct(buttonText);
506 pTextElement->SetTextColor(*textColor);
507 pTextElement->SetFont(*font);
510 //get dimensions of the text
511 FloatDimension textDimension;
512 font->GetTextExtent(buttonText, buttonText.GetLength(), textDimension);
513 if(textFontStyle != FONT_KEYPAD_NUMBER)
515 textDimension.height += font->GetDescender();
518 //create enriched text
519 EnrichedText* pEnrichedText = new (std::nothrow) EnrichedText();
520 pEnrichedText->Construct(textDimension);
521 pEnrichedText->Add(*pTextElement);
523 //set the position of the text in canvas
529 //Margin 13, rectangle for left text (13,0,77, height of canvas), center aligned
530 textPos.SetPosition(X_DIALER_BTN_TXT + ((W_DIALER_BTN_NUM_TXT - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
536 //rectangle for right text (13+77,0, 121, height of canvas), center aligned
537 textPos.SetPosition(X_DIALER_BTN_TXT + W_DIALER_BTN_NUM_TXT + ((121 - pEnrichedText->GetWidth()) / 2), (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
541 case POSITION_CENTER:
543 //rectangle for image : entire canvas, center aligned
544 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height - pEnrichedText->GetHeight()) / 2);
548 case POSITION_TOP_LEFT:
550 textPos.SetPosition(10, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
554 case POSITION_TOP_CENTER:
556 textPos.SetPosition((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2, (pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2);
560 case POSITION_BOTTOM_LEFT:
562 textPos.SetPosition(10, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
566 case POSITION_BOTTOM_CENTER:
568 int width = pEnrichedText->GetWidth();
569 if(width > W_ENRICHED_TEXT)
571 textPos.SetPosition(X_ENRICHED_TEXT, pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
575 textPos.SetPosition(10 + ((pCanvas.GetBounds().width - pEnrichedText->GetWidth()) / 2), pCanvas.GetBounds().height / 2 + ((pCanvas.GetBounds().height / 2 - pEnrichedText->GetHeight()) / 2));
580 case POSITION_SUGGESTION_NAME:
582 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
585 case POSITION_SUGGESTION_NUMBER:
587 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
593 //Draw EnrichedText to canvas
594 pCanvas.DrawText(textPos, *pEnrichedText);
597 pEnrichedText->RemoveAll(true);
598 delete pEnrichedText;
606 DialUtil::DrawCanvasToButton(Canvas* pCanvasNormal, Canvas* pCanvasPressed, Button* pButton)
608 Bitmap* pNormalBgBmp = new (std::nothrow) Bitmap();
609 pNormalBgBmp->Construct(*pCanvasNormal, pCanvasNormal->GetBounds());
611 pButton->SetNormalBackgroundBitmap(*pNormalBgBmp);
613 if (pCanvasPressed != null)
615 Bitmap* pPressedBgBmp = new (std::nothrow) Bitmap();
616 pPressedBgBmp->Construct(*pCanvasPressed, pCanvasPressed->GetBounds());
617 pButton->SetPressedBackgroundBitmap(*pPressedBgBmp);
618 delete pPressedBgBmp;
619 pPressedBgBmp = null;
623 pButton->SetPressedBackgroundBitmap(*pNormalBgBmp);
626 pButton->SetDisabledBitmap(Point(0, 0), *pNormalBgBmp);
627 pButton->Invalidate(true);
635 DialUtil::ConvertDialedNumberToString(int dialNumber)
711 DialUtil::FetchPossibleNamesListN(const String& prevSearchStr, int nextDigit)
713 //Fetch matching names for mapping char for digit, e.g. 2->ABC, 3->DEF.
714 ArrayList* pNamesList = new (std::nothrow) ArrayList(SingleObjectDeleter);
715 pNamesList->Construct(8);
717 if(nextDigit >=2 && nextDigit <= 9)
723 pNamesList->Add((new String(prevSearchStr+L"a")));
724 pNamesList->Add((new String(prevSearchStr+L"b")));
725 pNamesList->Add((new String(prevSearchStr+L"c")));
726 pNamesList->Add((new String(prevSearchStr+L"A")));
727 pNamesList->Add((new String(prevSearchStr+L"B")));
728 pNamesList->Add((new String(prevSearchStr+L"C")));
734 pNamesList->Add((new String(prevSearchStr+L"d")));
735 pNamesList->Add((new String(prevSearchStr+L"e")));
736 pNamesList->Add((new String(prevSearchStr+L"f")));
737 pNamesList->Add((new String(prevSearchStr+L"D")));
738 pNamesList->Add((new String(prevSearchStr+L"E")));
739 pNamesList->Add((new String(prevSearchStr+L"F")));
745 pNamesList->Add((new String(prevSearchStr+L"g")));
746 pNamesList->Add((new String(prevSearchStr+L"h")));
747 pNamesList->Add((new String(prevSearchStr+L"i")));
748 pNamesList->Add((new String(prevSearchStr+L"G")));
749 pNamesList->Add((new String(prevSearchStr+L"H")));
750 pNamesList->Add((new String(prevSearchStr+L"I")));
756 pNamesList->Add((new String(prevSearchStr+L"j")));
757 pNamesList->Add((new String(prevSearchStr+L"k")));
758 pNamesList->Add((new String(prevSearchStr+L"l")));
759 pNamesList->Add((new String(prevSearchStr+L"J")));
760 pNamesList->Add((new String(prevSearchStr+L"K")));
761 pNamesList->Add((new String(prevSearchStr+L"L")));
767 pNamesList->Add((new String(prevSearchStr+L"m")));
768 pNamesList->Add((new String(prevSearchStr+L"n")));
769 pNamesList->Add((new String(prevSearchStr+L"o")));
770 pNamesList->Add((new String(prevSearchStr+L"M")));
771 pNamesList->Add((new String(prevSearchStr+L"N")));
772 pNamesList->Add((new String(prevSearchStr+L"O")));
778 pNamesList->Add((new String(prevSearchStr+L"p")));
779 pNamesList->Add((new String(prevSearchStr+L"q")));
780 pNamesList->Add((new String(prevSearchStr+L"r")));
781 pNamesList->Add((new String(prevSearchStr+L"s")));
782 pNamesList->Add((new String(prevSearchStr+L"P")));
783 pNamesList->Add((new String(prevSearchStr+L"Q")));
784 pNamesList->Add((new String(prevSearchStr+L"R")));
785 pNamesList->Add((new String(prevSearchStr+L"S")));
791 pNamesList->Add((new String(prevSearchStr+L"t")));
792 pNamesList->Add((new String(prevSearchStr+L"u")));
793 pNamesList->Add((new String(prevSearchStr+L"v")));
794 pNamesList->Add((new String(prevSearchStr+L"T")));
795 pNamesList->Add((new String(prevSearchStr+L"U")));
796 pNamesList->Add((new String(prevSearchStr+L"V")));
802 pNamesList->Add((new String(prevSearchStr+L"w")));
803 pNamesList->Add((new String(prevSearchStr+L"x")));
804 pNamesList->Add((new String(prevSearchStr+L"y")));
805 pNamesList->Add((new String(prevSearchStr+L"z")));
806 pNamesList->Add((new String(prevSearchStr+L"W")));
807 pNamesList->Add((new String(prevSearchStr+L"X")));
808 pNamesList->Add((new String(prevSearchStr+L"Y")));
809 pNamesList->Add((new String(prevSearchStr+L"Z")));
819 DialUtil::ConvertNameToNumericKeys(String& subContactName, String& possibleKeysTyped)
821 for(int charPos=0;charPos < subContactName.GetLength();charPos++)
824 subContactName.GetCharAt(charPos,nextChar);
830 possibleKeysTyped.Append(2);
836 possibleKeysTyped.Append(3);
842 possibleKeysTyped.Append(4);
848 possibleKeysTyped.Append(5);
854 possibleKeysTyped.Append(6);
861 possibleKeysTyped.Append(7);
867 possibleKeysTyped.Append(8);
874 possibleKeysTyped.Append(9);
884 DialUtil::ConstructEnrichedTextN(String& text, String& matchedKeyword, int textFontStyle, Dimension txtDimension)
887 Font* fontName = DialUtil::GetTextFontN(textFontStyle);
889 Color* textColor = DialUtil::GetTextColorN(textFontStyle, BUTTON_STATUS_NORMAL);
890 //highlighted text Color
891 Color* highlightedTxtColor = DialUtil::GetTextColorN(FONT_HIGHLIGHT_SEARCH_KEYWORD, BUTTON_STATUS_NORMAL);
893 EnrichedText* pEnrichedName = new (std::nothrow) EnrichedText();
894 pEnrichedName->Construct(txtDimension);
895 pEnrichedName->SetTextWrapStyle(TEXT_WRAP_NONE);
896 //Text is divided in 3 parts - pre-text, highlighted matchedKeyword, post-text.
898 String highlightTxt(L"");
900 if(matchedKeyword.IsEmpty() == false)
903 result r = text.IndexOf(matchedKeyword,0,searchIndex);
908 text.SubString(0,searchIndex,preTxt);
910 text.SubString(searchIndex, matchedKeyword.GetLength(),highlightTxt);
911 text.SubString((searchIndex + matchedKeyword.GetLength()),postTxt);
919 TextElement* pTextName = null;
920 if(preTxt.IsEmpty() == false)
922 //create text element
923 pTextName = new (std::nothrow) TextElement();
924 pTextName->Construct(preTxt);
925 pTextName->SetFont(*fontName);
926 pTextName->SetTextColor(*textColor);
927 //ownership of 'pTextName' transferred to 'pEnrichedName'
928 pEnrichedName->Add(*pTextName);
931 if(highlightTxt.IsEmpty() == false)
933 //create text element
934 pTextName = new (std::nothrow) TextElement();
935 pTextName->Construct(highlightTxt);
936 pTextName->SetFont(*fontName);
937 // Highlighted search text
938 pTextName->SetTextColor(*highlightedTxtColor);
939 pEnrichedName->Add(*pTextName);
942 if(postTxt.IsEmpty() == false)
944 //create text element
945 pTextName = new (std::nothrow) TextElement();
946 pTextName->Construct(postTxt);
947 pTextName->SetFont(*fontName);
948 pTextName->SetTextColor(*textColor);
949 pEnrichedName->Add(*pTextName);
954 delete highlightedTxtColor;
956 return pEnrichedName;
960 DialUtil::DrawTextAndHighlightedKeywordToCanvas(String& buttonText, String& matchedKeyword, int textFontStyle, Canvas& pCanvas, int pos)
962 if (buttonText == null)
967 //Convert to enriched text with highlighted keyword
968 Dimension txtDimension (pCanvas.GetBounds().width - IDI_RIGHT_MARGIN_USE_CONTACT_BTN, H_USE_CONTACT_BTN);
969 EnrichedText* pEnrichedText = ConstructEnrichedTextN(buttonText, matchedKeyword, textFontStyle, txtDimension);
971 //set the position of the text in canvas
975 case POSITION_SUGGESTION_NAME:
977 textPos.SetPosition(X_LIST_DISPNAME,Y_LIST_DISPNAME);
981 case POSITION_SUGGESTION_NUMBER:
983 textPos.SetPosition(X_LIST_NUMBER,Y_LIST_NUMBER);
988 //Draw EnrichedText to canvas
989 pCanvas.DrawText(textPos, *pEnrichedText);
991 pEnrichedText->RemoveAll(true);
992 delete pEnrichedText;