X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/facd6764872eede45605ba7c9dfa0e1d0c708fa2..8ab505498d90cbedb2095d71f7a084d54300aba8:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index ffd659b5eb..211e778cba 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -769,6 +769,9 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, TXNSetSelection( (TXNObject) m_macTXN, 0, 0); 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 ) ; @@ -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() ; - - // Find line first - int count = 0; - for (size_t i = 0; i < content.Length() ; i++) + Point curpt ; + if ( lineNo < GetNumberOfLines() ) { - 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 ) { - // Count chars in line then - count = 0; - for (size_t j = i; j < content.Length(); j++) + TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt); + + if ( curpt.v > lastHeight ) { - count++; - if (content[j] == '\n') return count; + if ( ypos == lineNo ) + return xpos ; + + xpos = 0 ; + if ( n > 0 ) + ++ypos ; + lastHeight = curpt.v ; } - - return count; + else + ++xpos ; } - 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) + // 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 - wxString tmp; + TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt); - for (size_t j = i; j < content.Length(); j++) + if ( curpt.v > lastHeight ) { - if (content[j] == '\n') - return tmp; - - tmp += content[j]; + 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 ; } /*