Fixed GetLineLength and GetLineText for MLTE text controls - Fixed bug where it couldn't get the length or text of the first line (0) and sf bug 1030042 where subsequent lines to 0 would not include the first character. Added those tests to the text sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29339 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
385721a888
commit
ae25e5cc8c
@ -201,6 +201,27 @@ public:
|
|||||||
wxLogMessage(_T("Already at the top"));
|
wxLogMessage(_T("Already at the top"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnGetLine(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
long nLine = wxGetNumberFromUser(wxT("Which line would you like to get?"),
|
||||||
|
wxT("Enter which line you would like to get"),
|
||||||
|
wxT("Get a line from the tabbed multiline text control") );
|
||||||
|
|
||||||
|
wxMessageBox(m_panel->m_tab->GetLineText(nLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnGetLineLength(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
long nLine = wxGetNumberFromUser(wxT("Which line would you like to get?"),
|
||||||
|
wxT("Enter which line you would like to get"),
|
||||||
|
wxT("Get length of a line from the tabbed multiline text control") );
|
||||||
|
|
||||||
|
wxMessageBox(wxString::Format(wxT("Length of line %i is:%i"),
|
||||||
|
(int) nLine,
|
||||||
|
m_panel->m_tab->GetLineLength(nLine))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_LOG
|
#if wxUSE_LOG
|
||||||
void OnLogClear(wxCommandEvent& event);
|
void OnLogClear(wxCommandEvent& event);
|
||||||
#endif // wxUSE_LOG
|
#endif // wxUSE_LOG
|
||||||
@ -336,6 +357,10 @@ enum
|
|||||||
TEXT_LINE_UP,
|
TEXT_LINE_UP,
|
||||||
TEXT_PAGE_DOWN,
|
TEXT_PAGE_DOWN,
|
||||||
TEXT_PAGE_UP,
|
TEXT_PAGE_UP,
|
||||||
|
|
||||||
|
TEXT_GET_LINE,
|
||||||
|
TEXT_GET_LINELENGTH,
|
||||||
|
|
||||||
TEXT_REMOVE,
|
TEXT_REMOVE,
|
||||||
TEXT_REPLACE,
|
TEXT_REPLACE,
|
||||||
TEXT_SELECT,
|
TEXT_SELECT,
|
||||||
@ -411,6 +436,9 @@ bool MyApp::OnInit()
|
|||||||
menuText->Append(TEXT_LINE_UP, _T("Scroll text one line up"));
|
menuText->Append(TEXT_LINE_UP, _T("Scroll text one line up"));
|
||||||
menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page down"));
|
menuText->Append(TEXT_PAGE_DOWN, _T("Scroll text one page down"));
|
||||||
menuText->Append(TEXT_PAGE_UP, _T("Scroll text one page up"));
|
menuText->Append(TEXT_PAGE_UP, _T("Scroll text one page up"));
|
||||||
|
menuText->AppendSeparator();
|
||||||
|
menuText->Append(TEXT_GET_LINE, _T("Get the text of a line of the tabbed multiline"));
|
||||||
|
menuText->Append(TEXT_GET_LINELENGTH, _T("Get the length of a line of the tabbed multiline"));
|
||||||
menu_bar->Append(menuText, _T("Te&xt"));
|
menu_bar->Append(menuText, _T("Te&xt"));
|
||||||
|
|
||||||
#if wxUSE_LOG
|
#if wxUSE_LOG
|
||||||
@ -1212,6 +1240,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(TEXT_PAGE_DOWN, MyFrame::OnScrollPageDown)
|
EVT_MENU(TEXT_PAGE_DOWN, MyFrame::OnScrollPageDown)
|
||||||
EVT_MENU(TEXT_PAGE_UP, MyFrame::OnScrollPageUp)
|
EVT_MENU(TEXT_PAGE_UP, MyFrame::OnScrollPageUp)
|
||||||
|
|
||||||
|
EVT_MENU(TEXT_GET_LINE, MyFrame::OnGetLine)
|
||||||
|
EVT_MENU(TEXT_GET_LINELENGTH, MyFrame::OnGetLineLength)
|
||||||
|
|
||||||
EVT_MENU(TEXT_SET, MyFrame::OnSetText)
|
EVT_MENU(TEXT_SET, MyFrame::OnSetText)
|
||||||
|
|
||||||
EVT_IDLE(MyFrame::OnIdle)
|
EVT_IDLE(MyFrame::OnIdle)
|
||||||
|
@ -1804,41 +1804,37 @@ void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOff
|
|||||||
wxString wxMacMLTEControl::GetLineText(long lineNo) const
|
wxString wxMacMLTEControl::GetLineText(long lineNo) const
|
||||||
{
|
{
|
||||||
wxString line ;
|
wxString line ;
|
||||||
Point curpt ;
|
|
||||||
wxString content = GetStringValue() ;
|
|
||||||
|
|
||||||
if ( lineNo < GetNumberOfLines() )
|
if ( lineNo < GetNumberOfLines() )
|
||||||
{
|
{
|
||||||
// TODO find a better implementation : while we can get the
|
|
||||||
// line metrics of a certain line, we don't get its starting
|
|
||||||
// position, so it would probably be rather a binary search
|
|
||||||
// for the start position
|
|
||||||
long xpos = 0 ;
|
|
||||||
long ypos = 0 ;
|
long ypos = 0 ;
|
||||||
int lastHeight = 0 ;
|
|
||||||
long lastpos = GetLastPosition() ;
|
|
||||||
|
|
||||||
ItemCount n ;
|
Fixed lineWidth,
|
||||||
for ( n = 0 ; n <= (ItemCount)lastpos ; ++n )
|
lineHeight,
|
||||||
|
currentHeight = 0;
|
||||||
|
|
||||||
|
// get the first possible position in the control
|
||||||
|
Point firstPoint;
|
||||||
|
TXNOffsetToPoint(m_txn, 0, &firstPoint);
|
||||||
|
|
||||||
|
// Iterate through the lines until we reach the one we want,
|
||||||
|
// adding to our current y pixel point position
|
||||||
|
while (ypos < lineNo)
|
||||||
{
|
{
|
||||||
TXNOffsetToPoint( m_txn, n , &curpt);
|
TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
|
||||||
|
currentHeight += lineHeight;
|
||||||
if ( curpt.v > lastHeight )
|
|
||||||
{
|
|
||||||
if ( ypos == lineNo )
|
|
||||||
return line ;
|
|
||||||
|
|
||||||
xpos = 0 ;
|
|
||||||
if ( n > 0 )
|
|
||||||
++ypos ;
|
|
||||||
lastHeight = curpt.v ;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
Point thePoint = { firstPoint.v + Fix2Long(currentHeight), firstPoint.h + Fix2Long(0) };
|
||||||
|
TXNOffset theOffset;
|
||||||
|
TXNPointToOffset(m_txn, thePoint, &theOffset);
|
||||||
|
|
||||||
|
wxString content = GetStringValue() ;
|
||||||
|
Point currentPoint = thePoint;
|
||||||
|
while(thePoint.v == currentPoint.v && theOffset < content.length())
|
||||||
{
|
{
|
||||||
if ( ypos == lineNo )
|
line += content[theOffset];
|
||||||
line += content[n] ;
|
TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint);
|
||||||
++xpos ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return line ;
|
return line ;
|
||||||
@ -1846,38 +1842,41 @@ wxString wxMacMLTEControl::GetLineText(long lineNo) const
|
|||||||
|
|
||||||
int wxMacMLTEControl::GetLineLength(long lineNo) const
|
int wxMacMLTEControl::GetLineLength(long lineNo) const
|
||||||
{
|
{
|
||||||
Point curpt ;
|
int theLength = 0;
|
||||||
|
|
||||||
if ( lineNo < GetNumberOfLines() )
|
if ( lineNo < GetNumberOfLines() )
|
||||||
{
|
{
|
||||||
// TODO find a better implementation : while we can get the
|
|
||||||
// line metrics of a certain line, we don't get its starting
|
|
||||||
// position, so it would probably be rather a binary search
|
|
||||||
// for the start position
|
|
||||||
long xpos = 0 ;
|
|
||||||
long ypos = 0 ;
|
long ypos = 0 ;
|
||||||
int lastHeight = 0 ;
|
|
||||||
long lastpos = GetLastPosition() ;
|
|
||||||
|
|
||||||
ItemCount n ;
|
Fixed lineWidth,
|
||||||
for ( n = 0 ; n <= (ItemCount) lastpos ; ++n )
|
lineHeight,
|
||||||
|
currentHeight = 0;
|
||||||
|
|
||||||
|
// get the first possible position in the control
|
||||||
|
Point firstPoint;
|
||||||
|
TXNOffsetToPoint(m_txn, 0, &firstPoint);
|
||||||
|
|
||||||
|
// Iterate through the lines until we reach the one we want,
|
||||||
|
// adding to our current y pixel point position
|
||||||
|
while (ypos < lineNo)
|
||||||
{
|
{
|
||||||
TXNOffsetToPoint( m_txn , n , &curpt);
|
TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
|
||||||
|
currentHeight += lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
if ( curpt.v > lastHeight )
|
Point thePoint = { firstPoint.v + Fix2Long(currentHeight), firstPoint.h + Fix2Long(0) };
|
||||||
|
TXNOffset theOffset;
|
||||||
|
TXNPointToOffset(m_txn, thePoint, &theOffset);
|
||||||
|
|
||||||
|
wxString content = GetStringValue() ;
|
||||||
|
Point currentPoint = thePoint;
|
||||||
|
while(thePoint.v == currentPoint.v && theOffset < content.length())
|
||||||
{
|
{
|
||||||
if ( ypos == lineNo )
|
++theLength;
|
||||||
return xpos ;
|
TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint);
|
||||||
|
|
||||||
xpos = 0 ;
|
|
||||||
if ( n > 0 )
|
|
||||||
++ypos ;
|
|
||||||
lastHeight = curpt.v ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++xpos ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0 ;
|
return theLength ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user