Esempio n. 1
0
EnrichedText* JMChattControl::StringToEnrichedText(String strText, Color colorText)
{
	result r = E_SUCCESS;


	int nTextWidth = __stScreenInfo.nTextBoxWidth - (__stScreenInfo.nTextBoxInsideGap * 2);
	Dimension dimText;

	__stScreenInfo.fontText.GetTextExtent(strText, strText.GetLength(), dimText);
	if( dimText.width < nTextWidth )
		nTextWidth = dimText.width;

	EnrichedText* pEnrichedText = null;
	TextElement* pTextElement1 = null;
	pEnrichedText = new EnrichedText();
	r = pEnrichedText->Construct(Dimension(nTextWidth, __stScreenInfo.rtScreen.height));
	if (IsFailed(r)) {
		return null;
	}
	pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
	pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
	pEnrichedText->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
	pEnrichedText->SetTextAbbreviationEnabled(false);

	// Create a TextElement and set attributes.
	pTextElement1 = new TextElement();
	r = pTextElement1->Construct(strText);
	if (IsFailed(r)) {
		return null;
	}
	pTextElement1->SetTextColor(colorText);
	pTextElement1->SetFont(__stScreenInfo.fontText);
	// Add the TextElement to the EnrichedText
	pEnrichedText->Add(*pTextElement1);


	pEnrichedText->SetSize(nTextWidth, pEnrichedText->GetTotalLineHeight());

	return pEnrichedText;
}