Getting the current page number in TextEdit
Getting the current page number in TextEdit
- Subject: Getting the current page number in TextEdit
- From: email@hidden
- Date: Mon, 14 Aug 2006 18:48:45 +0200 (CEST)
- Importance: Normal
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden