AUI_ERRCODE aui_HyperTextBase::AddHyperStatics( const MBCHAR *hyperText )
{
	if ( !hyperText )
	{
		RemoveHyperStatics();
		hyperText = m_hyperText;
	}

	sint32 len = strlen( hyperText );
	if ( !len ) return AUI_ERRCODE_OK;

	aui_Static *hs = CreateHyperStatic(
		hyperText,
		len,
		m_hyperTtffile,
		m_hyperPointSize,
		m_hyperBold,
		m_hyperItalic,
		m_hyperColor,
		m_hyperUnderline,
		m_hyperShadow,
		m_hyperShadowColor,
		m_hyperFlags );
	Assert( hs != NULL );
	if ( !hs ) return AUI_ERRCODE_MEMALLOCFAILED;

	m_hyperStaticList->AddTail( hs );

	if ( m_hyperStaticList->L() > k_AUI_HYPERTEXTBOX_LDL_MAXSTATICS )
    {
		delete m_hyperStaticList->RemoveHead();
    }

	return AUI_ERRCODE_OK;
}
aui_HyperTextBase::~aui_HyperTextBase()
{
	delete [] m_hyperText;

	if (m_hyperStaticList)
	{
		RemoveHyperStatics();
		delete m_hyperStaticList;
	}
}
Esempio n. 3
0
AUI_ERRCODE ctp2_HyperTextBox::AddHyperStatics( const MBCHAR *hyperText )
{
	if (!hyperText)
	{
		RemoveHyperStatics();
		RemoveHyperLinks();
		m_curStaticPos.x = 0;
		m_curStaticPos.y = 0;
		m_virtualHeight = 0;
		hyperText = m_hyperText;
	}

	uint32 len = strlen( hyperText );
	if ( !len ) return AUI_ERRCODE_OK;

	const MBCHAR *ptr = hyperText;
	const MBCHAR *stop = ptr + len;



	sint32      hyperLinkDB     = 0;
	sint32      hyperLinkIndex  = CTPRecord::INDEX_INVALID;
	bool        isHyperLink     = false;
	COLORREF    oldColor        = 0;
	sint32      oldUnderline    = 0;

	while ( ptr != stop )
	{
		if ( *ptr == '<' )
		{
			switch ( *++ptr )
			{
			case 't':
				sscanf( ++ptr, ":%[^>]", m_hyperTtffile );
				break;

			case 'p':
				sscanf( ++ptr, ":%d>", &m_hyperPointSize );
				break;

			case 'b':
				sscanf( ++ptr, ":%d>", &m_hyperBold );
				break;

			case 'i':
				sscanf( ++ptr, ":%d>", &m_hyperItalic );
				break;

			case 'c':
			{
				uint8 r, g, b;
				sscanf( ++ptr, ":%u,%u,%u>", &r, &g, &b );
				m_hyperColorOld = m_hyperColor;
				m_hyperColor    = RGB(r,g,b);
			}
			break;

			
			case 's':
				sscanf( ++ptr, ":%d>", &m_hyperShadow );
				break;

			
			case 'h':
			{
				uint8 r, g, b;
				sscanf( ++ptr, ":%u,%u,%u>", &r, &g, &b );
				m_hyperShadowColor = RGB(r,g,b);
			}
			break;

			case 'u':
				sscanf( ++ptr, ":%d>", &m_hyperUnderline );
				break;

			
			case 'l':
				sscanf( ++ptr, ":%d,%d>", &hyperLinkDB, &hyperLinkIndex );
				
				oldUnderline        = m_hyperUnderline;
				oldColor            = m_hyperColor;
				m_hyperColorOld     = m_hyperColor;

				m_hyperUnderline    = 1;
				m_hyperColor        = RGB(0,0,100);
				isHyperLink         = true;
				break;

			
			
			case 'L':
				{

				
				MBCHAR			hyperLinkDB_name[GL_MAX_DB_NAME_SIZE];
				MBCHAR			hyperLinkIndex_name[MAX_SIZE_IDENTIFIER + 1];
				MBCHAR const *	copyBegin;
				MBCHAR const *	copyEnd;
				MBCHAR const *	copySafeEnd; 
				
				copyBegin	= std::find_if(ptr + 2, stop, IsIdentifierBegin);
				copyEnd		= std::find_if(copyBegin, stop, IsNotInIdentifier);
				copySafeEnd	= std::min(copyEnd, copyBegin + GL_MAX_DB_NAME_SIZE);

				std::copy(copyBegin, copySafeEnd, hyperLinkDB_name);
				std::fill(hyperLinkDB_name + (copySafeEnd - copyBegin),
						  hyperLinkDB_name + GL_MAX_DB_NAME_SIZE,
						  static_cast<MBCHAR const>(0)
						 );

				copyBegin	= std::find_if(copyEnd, stop, IsIdentifierBegin);
				copyEnd		= std::find_if(copyBegin, stop, IsNotInIdentifier);
				copySafeEnd	= std::min(copyEnd, copyBegin + MAX_SIZE_IDENTIFIER);

				std::copy(copyBegin, copySafeEnd, hyperLinkIndex_name);
				std::fill(hyperLinkIndex_name + (copySafeEnd - copyBegin),
						  hyperLinkIndex_name + MAX_SIZE_IDENTIFIER + 1,
						  static_cast<MBCHAR const>(0)
						 );

				ptr			= std::find(copyEnd, stop, '>');

				hyperLinkDB         = 
                    GreatLibrary::Get_Database_From_Name(hyperLinkDB_name);
				hyperLinkIndex      = 
					GreatLibrary::Get_Object_Index_From_Name(hyperLinkDB, hyperLinkIndex_name);
				oldUnderline        = m_hyperUnderline;
				oldColor            = m_hyperColor;
				m_hyperColorOld     = m_hyperColor;
				m_hyperUnderline    = 1;
				m_hyperColor        = RGB(0,0,100);
				isHyperLink         = true;
				break;
				}

			case 'e':
				if (isHyperLink)
				{
					// <L> or <l> directly followed by <e>.
					// Perform database text lookup.
					if (hyperLinkDB)
					{
						MBCHAR const *	ptr	= g_greatLibrary->GetObjectName
												(hyperLinkDB, hyperLinkIndex);
						
						FormatText(ptr, 
							       ptr + strlen(ptr), 
								   hyperLinkDB, 
								   hyperLinkIndex, 
								   true
								  );

					}

					m_hyperUnderline	= oldUnderline;
					isHyperLink			= false;
				}
				m_hyperColor = m_hyperColorOld;
				break;

			default:
				
				Assert( FALSE );
				return AUI_ERRCODE_INVALIDPARAM;
			}

			ptr = std::find(ptr, stop, '>');
			if (ptr != stop)
			{
				++ptr;
			}
		}
		else
		{

			MBCHAR const *  nextLine	= std::find(ptr, stop, '\n');
			MBCHAR const *	nextStop	= std::find(ptr, nextLine, '<');

			if ((nextStop != stop) && (*nextStop == '\n'))
			{
				// Include the end of line marker in the string
				++nextStop;
			}

			FormatText(ptr, nextStop, hyperLinkDB, hyperLinkIndex, isHyperLink);
			ptr	= nextStop;

			if (isHyperLink) 
            {
				isHyperLink         = false;
				m_hyperUnderline    = oldUnderline;
				m_hyperColor        = oldColor;
			}
		}
	}

	return AUI_ERRCODE_OK;
}