* Find the document position corresponding to an x coordinate on a particular document line. * Ensure is between whole characters when document is in multi-byte or UTF-8 mode. */
| 613 | * Ensure is between whole characters when document is in multi-byte or UTF-8 mode. |
| 614 | */ |
| 615 | SelectionPosition Editor::SPositionFromLineX ( int lineDoc, int x ) |
| 616 | { |
| 617 | RefreshStyleData(); |
| 618 | if ( lineDoc >= pdoc->LinesTotal() ) { |
| 619 | return SelectionPosition ( pdoc->Length() ); |
| 620 | } |
| 621 | //Platform::DebugPrintf("Position of (%d,%d) line = %d top=%d\n", pt.x, pt.y, line, topLine); |
| 622 | AutoSurface surface ( this ); |
| 623 | AutoLineLayout ll ( llc, RetrieveLineLayout ( lineDoc ) ); |
| 624 | int retVal = 0; |
| 625 | if ( surface && ll ) { |
| 626 | unsigned int posLineStart = pdoc->LineStart ( lineDoc ); |
| 627 | LayoutLine ( lineDoc, surface, vs, ll, wrapWidth ); |
| 628 | int subLine = 0; |
| 629 | int lineStart = ll->LineStart ( subLine ); |
| 630 | int lineEnd = ll->LineLastVisible ( subLine ); |
| 631 | XYPOSITION subLineStart = ll->positions[lineStart]; |
| 632 | XYPOSITION newX = x; |
| 633 | if ( ll->wrapIndent != 0 ) { |
| 634 | if ( lineStart != 0 ) { // Wrapped |
| 635 | newX -= ll->wrapIndent; |
| 636 | } |
| 637 | } |
| 638 | int i = ll->FindBefore ( newX + subLineStart, lineStart, lineEnd ); |
| 639 | while ( i < lineEnd ) { |
| 640 | if ( ( newX + subLineStart ) < ( ( ll->positions[i] + ll->positions[i + 1] ) / 2 ) ) { |
| 641 | retVal = pdoc->MovePositionOutsideChar ( i + posLineStart, 1 ); |
| 642 | return SelectionPosition ( retVal ); |
| 643 | } |
| 644 | i++; |
| 645 | } |
| 646 | const XYPOSITION spaceWidth = vs.styles[ll->EndLineStyle()].spaceWidth; |
| 647 | int spaceOffset = ( newX + subLineStart - ll->positions[lineEnd] + spaceWidth / 2 ) / spaceWidth; |
| 648 | return SelectionPosition ( lineEnd + posLineStart, spaceOffset ); |
| 649 | } |
| 650 | return SelectionPosition ( retVal ); |
| 651 | } |
| 652 | |
| 653 | int Editor::PositionFromLineX ( int lineDoc, int x ) |
| 654 | { |
nothing calls this directly
no test coverage detected