added first bare bones implementation for PositionToXY and friends
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26434 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
949cb163a7
commit
bd3169a752
@ -770,6 +770,9 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
|
||||
TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart);
|
||||
}
|
||||
|
||||
// in case MLTE is catching events before we get the chance to do so, we'd have to reintroduce the tlw-handler in front :
|
||||
// parent->MacGetTopLevelWindow()->MacInstallTopLevelWindowEventHandler() ;
|
||||
|
||||
SetBackgroundColour( *wxWHITE ) ;
|
||||
|
||||
TXNBackground tback;
|
||||
@ -1322,12 +1325,78 @@ int wxTextCtrl::GetNumberOfLines() const
|
||||
|
||||
long wxTextCtrl::XYToPosition(long x, long y) const
|
||||
{
|
||||
// TODO
|
||||
Point curpt ;
|
||||
|
||||
long lastpos = GetLastPosition() ;
|
||||
|
||||
// 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 ;
|
||||
int lastHeight = 0 ;
|
||||
|
||||
ItemCount n ;
|
||||
for ( n = 0 ; n <= lastpos ; ++n )
|
||||
{
|
||||
if ( y == ypos && x == xpos )
|
||||
return n ;
|
||||
|
||||
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
|
||||
|
||||
if ( curpt.v > lastHeight )
|
||||
{
|
||||
xpos = 0 ;
|
||||
if ( n > 0 )
|
||||
++ypos ;
|
||||
lastHeight = curpt.v ;
|
||||
}
|
||||
else
|
||||
++xpos ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
|
||||
{
|
||||
Point curpt ;
|
||||
|
||||
long lastpos = GetLastPosition() ;
|
||||
|
||||
if ( y ) *y = 0 ;
|
||||
if ( x ) *x = 0 ;
|
||||
|
||||
if ( pos <= lastpos )
|
||||
{
|
||||
// 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 ;
|
||||
int lastHeight = 0 ;
|
||||
|
||||
ItemCount n ;
|
||||
for ( n = 0 ; n <= pos ; ++n )
|
||||
{
|
||||
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
|
||||
|
||||
if ( curpt.v > lastHeight )
|
||||
{
|
||||
xpos = 0 ;
|
||||
if ( n > 0 )
|
||||
++ypos ;
|
||||
lastHeight = curpt.v ;
|
||||
}
|
||||
else
|
||||
++xpos ;
|
||||
}
|
||||
if ( y ) *y = ypos ;
|
||||
if ( x ) *x = xpos ;
|
||||
}
|
||||
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
@ -1357,57 +1426,83 @@ void wxTextCtrl::ShowPosition(long pos)
|
||||
|
||||
int wxTextCtrl::GetLineLength(long lineNo) const
|
||||
{
|
||||
// TODO change this if possible to reflect real lines
|
||||
wxString content = GetValue() ;
|
||||
Point curpt ;
|
||||
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 ;
|
||||
int lastHeight = 0 ;
|
||||
long lastpos = GetLastPosition() ;
|
||||
|
||||
// Find line first
|
||||
int count = 0;
|
||||
for (size_t i = 0; i < content.Length() ; i++)
|
||||
ItemCount n ;
|
||||
for ( n = 0 ; n <= lastpos ; ++n )
|
||||
{
|
||||
if (count == lineNo)
|
||||
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
|
||||
|
||||
if ( curpt.v > lastHeight )
|
||||
{
|
||||
// Count chars in line then
|
||||
count = 0;
|
||||
for (size_t j = i; j < content.Length(); j++)
|
||||
{
|
||||
count++;
|
||||
if (content[j] == '\n') return count;
|
||||
if ( ypos == lineNo )
|
||||
return xpos ;
|
||||
|
||||
xpos = 0 ;
|
||||
if ( n > 0 )
|
||||
++ypos ;
|
||||
lastHeight = curpt.v ;
|
||||
}
|
||||
else
|
||||
++xpos ;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
if (content[i] == '\n') count++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
wxString wxTextCtrl::GetLineText(long lineNo) const
|
||||
{
|
||||
// TODO change this if possible to reflect real lines
|
||||
Point curpt ;
|
||||
wxString line ;
|
||||
wxString content = GetValue() ;
|
||||
|
||||
// Find line first
|
||||
int count = 0;
|
||||
for (size_t i = 0; i < content.Length() ; i++)
|
||||
if ( lineNo < GetNumberOfLines() )
|
||||
{
|
||||
if (count == lineNo)
|
||||
{
|
||||
// Add chars in line then
|
||||
wxString tmp;
|
||||
// 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 ;
|
||||
int lastHeight = 0 ;
|
||||
long lastpos = GetLastPosition() ;
|
||||
|
||||
for (size_t j = i; j < content.Length(); j++)
|
||||
ItemCount n ;
|
||||
for ( n = 0 ; n <= lastpos ; ++n )
|
||||
{
|
||||
if (content[j] == '\n')
|
||||
return tmp;
|
||||
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
|
||||
|
||||
tmp += content[j];
|
||||
if ( curpt.v > lastHeight )
|
||||
{
|
||||
if ( ypos == lineNo )
|
||||
return line ;
|
||||
|
||||
xpos = 0 ;
|
||||
if ( n > 0 )
|
||||
++ypos ;
|
||||
lastHeight = curpt.v ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ypos == lineNo )
|
||||
line += content[n] ;
|
||||
++xpos ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
if (content[i] == '\n') count++;
|
||||
}
|
||||
return wxEmptyString ;
|
||||
return line ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user