• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Getting the current page number in TextEdit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: [SOLVED]Re: releasing NSXMLParser
  • Next by Date: Re: QTKit and QTMedia information?
  • Previous by thread: Problem with -setMovableByWindowBackgound: method.
  • Next by thread: Best practice for WORM entities?
  • Index(es):
    • Date
    • Thread