Skip navigation.
 
mlGetting the current page number in TextEdit
FROM : delanoy
DATE : Mon Aug 14 18:48:45 2006

Hello all,

  I wrote the code below to get the page number in "Wrap To Page" mode in
TextEdit
(determined by  the current location of the cursor).
It doesn't work (the method below, which should yield the current
page number, always returns 1). Does anyone guess at a glance what's wrong
with this code ?

  /*code added inside Document.m, from the source code in
/Developer/Examples/AppKit/TextEdit.
It would be more logical to define this as a method of class
MultiplePageView, but this is a detail. */

- (unsigned)currentPageNumber
{


     MultiplePageView* pagesView=[scrollView documentView];
     NSTextView* textView=[self firstTextView];
     NSRange range=[textView selectedRange];

      range.length=1; /* range.location indicates where the cursor is */
     NSRect rectInTextView=[textView firstRectForCharacterRange:range];
     NSRect rectInMPView=[pagesView convertRect:rectInTextView
fromView:textView];
     NSPoint currentPoint=rectInMPView.origin;

     unsigned cnt=[pagesView numberOfPages];
     unsigned i;
     for (i=1;i<cnt;i++) {
         if (NSPointInRect(currentPoint,[pagesView rectForPage:i])) {
               return i;
         }
     }
     /*should be unreachable*/
     return 0;
}

                                                                          Ewan

Related mailsAuthorDate
No related mails found.