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:
Stefan Csomor
2004-03-28 17:52:10 +00:00
parent 949cb163a7
commit bd3169a752

View File

@@ -769,6 +769,9 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
TXNSetSelection( (TXNObject) m_macTXN, 0, 0); TXNSetSelection( (TXNObject) m_macTXN, 0, 0);
TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart); 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 ) ; SetBackgroundColour( *wxWHITE ) ;
@@ -1322,12 +1325,78 @@ int wxTextCtrl::GetNumberOfLines() const
long wxTextCtrl::XYToPosition(long x, long y) 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; return 0;
} }
bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const 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 ; return FALSE ;
} }
@@ -1357,57 +1426,83 @@ void wxTextCtrl::ShowPosition(long pos)
int wxTextCtrl::GetLineLength(long lineNo) const int wxTextCtrl::GetLineLength(long lineNo) const
{ {
// TODO change this if possible to reflect real lines Point curpt ;
wxString content = GetValue() ; if ( lineNo < GetNumberOfLines() )
// Find line first
int count = 0;
for (size_t i = 0; i < content.Length() ; i++)
{ {
if (count == lineNo) // TODO find a better implementation : while we can get the
{ // line metrics of a certain line, we don't get its starting
// Count chars in line then // position, so it would probably be rather a binary search
count = 0; // for the start position
for (size_t j = i; j < content.Length(); j++) long xpos = 0 ;
{ long ypos = 0 ;
count++; int lastHeight = 0 ;
if (content[j] == '\n') return count; long lastpos = GetLastPosition() ;
}
return count; ItemCount n ;
for ( n = 0 ; n <= lastpos ; ++n )
{
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
if ( curpt.v > lastHeight )
{
if ( ypos == lineNo )
return xpos ;
xpos = 0 ;
if ( n > 0 )
++ypos ;
lastHeight = curpt.v ;
}
else
++xpos ;
} }
if (content[i] == '\n') count++;
} }
return 0; return 0;
} }
wxString wxTextCtrl::GetLineText(long lineNo) const wxString wxTextCtrl::GetLineText(long lineNo) const
{ {
// TODO change this if possible to reflect real lines Point curpt ;
wxString line ;
wxString content = GetValue() ; wxString content = GetValue() ;
// Find line first if ( lineNo < GetNumberOfLines() )
int count = 0;
for (size_t i = 0; i < content.Length() ; i++)
{ {
if (count == lineNo) // 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() ;
ItemCount n ;
for ( n = 0 ; n <= lastpos ; ++n )
{ {
// Add chars in line then TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
wxString tmp;
for (size_t j = i; j < content.Length(); j++) if ( curpt.v > lastHeight )
{ {
if (content[j] == '\n') if ( ypos == lineNo )
return tmp; return line ;
tmp += content[j]; 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 ;
} }
/* /*