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; }
//---------------------------------------------------------------------------- // // Name : ctp2_HyperTextBox::FormatText // // Description: Format a text by wrapping it into a text box. // // Parameters : a_Text : start of text to add // a_TextEnd : (one past) end of text to add // a_Database : link to database // a_Index : link to index within database // a_IsLink : text is a hyperlink // // Globals : - // // Returns : - // // Remark(s) : - // //---------------------------------------------------------------------------- void ctp2_HyperTextBox::FormatText ( MBCHAR const * a_Text, MBCHAR const * a_TextEnd, sint32 a_Database, sint32 a_Index, bool a_IsLink ) { for (MBCHAR const * ptr = a_Text; ptr < a_TextEnd; ) { aui_Static * hs = CreateHyperStatic(ptr, a_TextEnd - ptr, // may be corrected later m_hyperTtffile, m_hyperPointSize, m_hyperBold, m_hyperItalic, m_hyperColor, m_hyperUnderline, m_hyperShadow, m_hyperShadowColor, m_hyperFlags ); Assert(hs); if (!hs) return; MBCHAR * cReturn = strrchr(hs->GetText(), '\r'); if (cReturn) { *cReturn = ' '; } m_hyperStaticList->AddTail(hs); sint32 nextX = m_curStaticPos.x + hs->Width(); sint32 nextY = m_curStaticPos.y + hs->Height(); if (nextX <= m_width) { // The whole text will fit on the current line. hs->Move(m_curStaticPos.x, m_curStaticPos.y); m_curStaticPos.x = nextX; if (nextY > m_virtualHeight) { m_virtualHeight = nextY; } ptr = a_TextEnd; } else { RECT wrap = { 0, 0, m_width - m_curStaticPos.x, 0 }; POINT penPos = { 0, 0 }; MBCHAR const * start = ptr; hs->GetTextFont()->GetLineInfo (&wrap, &penPos, NULL, NULL, &ptr, a_TextEnd); if (ptr == a_TextEnd) { // Not even the first word will fit on the current line. hs->Move(m_curStaticPos.x = 0, m_curStaticPos.y = m_virtualHeight ); m_virtualHeight += hs->Height(); if (hs->Width() > m_width) { m_curStaticPos.y = m_virtualHeight; } else { m_curStaticPos.x = hs->Width(); } } else { // The section from start to ptr may fit on the current line. MBCHAR const * testPtr = start; MBCHAR const * testSubStop = ptr; penPos.x = 0; penPos.y = 0; hs->GetTextFont()->GetLineInfo (&wrap, &penPos, NULL, NULL, &testPtr, testSubStop); if (penPos.x > wrap.right) { // Move everything to the next line. hs->Move(m_curStaticPos.x = 0, m_curStaticPos.y = m_virtualHeight ); m_virtualHeight += hs->Height(); if (hs->Width() > m_width) { m_curStaticPos.y = m_virtualHeight; } else { m_curStaticPos.x = hs->Width(); } ptr = a_TextEnd; } else { // Put a part on this line, and continue on the next line. hs->SetText(start, ptr - start); hs->Move(m_curStaticPos.x, m_curStaticPos.y); hs->Resize(penPos.x, hs->Height()); if (nextY > m_virtualHeight) { m_virtualHeight = nextY; } m_curStaticPos.x = 0; m_curStaticPos.y = m_virtualHeight; } } } // Check for line breaks if (*(ptr - 1) == '\n') { m_curStaticPos.x = 0; m_curStaticPos.y = m_virtualHeight; } // Removed the arbitrary limit of k_AUI_HYPERTEXTBOX_LDL_MAXSTATICS // (= 100) hyperstatic list items, because it resulted in a mismatch // between the hyperstatic and hyperlink lists, causing a crash later. if (a_IsLink) { ctp2_HyperLink * hl = new ctp2_HyperLink; hl->m_static = hs; hl->m_db = a_Database; hl->m_index = a_Index; hl->m_frame = FALSE; hl->m_oldColor = m_hyperColor; hl->m_selectColor = RGB(0,0,255); m_hyperLinkList->AddTail(hl); } } // for }