Re: PDFView drawPage called often after selecting text
Re: PDFView drawPage called often after selecting text
- Subject: Re: PDFView drawPage called often after selecting text
- From: Martin Hewitson <email@hidden>
- Date: Wed, 09 Jan 2013 08:43:32 +0100
Andy, Kyle,
Thank you both for your assistance on this. I've got something working now which doesn't cause the responsiveness issues and even looks visually more pleasant. Here's the solution:
- (void) drawPagePost:(PDFPage *)page {
[super drawPagePost:page];
if ([[self window] firstResponder] == self && [NSApp isActive]) {
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
NSRect r = [[self documentView] bounds];
[[NSBezierPath bezierPathWithRect:r] fill];
[NSGraphicsContext restoreGraphicsState];
}
}
This puts a nice focus ring tightly around the pdf pages, rather than hugging the edges of the PDFView. I find this much nicer and easier to see.
Some interesting points/problems
- if I use -drawPage: instead, then the focus ring has the wrong size and overlaps the displayed pages. Don't know why.
- doing this in -drawPage: or -drawPagePost: solves the issue I was having
- using [self bounds] rather than [[self documentView] bounds] produces no visible focus ring
Anyway, I'm now happy with the results, though I would like to understand better why the other possible 'solutions' don't work.
Best wishes,
Martin
On Jan 8, 2013, at 05:22 PM, Kyle Sluder <email@hidden> wrote:
> On Tue, Jan 8, 2013, at 07:58 AM, Andy Lee wrote:
>> You're already calling setKeyboardFocusRingNeedsDisplayInRect: in
>> become/resignFirstResponder, which seems like the right place. But I
>> notice Apple's "Dicey" example project uses NSSetFocusRingStyle
>> differently than you do. It pushes and pops the graphics state -- and
>> thus, I believe, the clipping region -- instead of doing lockFocus on the
>> superview. I bet this is how it avoids the infinite invalidating.
>
> Well, pushing the graphics state isn't going to reset the clipping rect,
> and -lockFocus pushes a new graphics state on the stack anyway.
>
>>
>> I think Kyle is suggesting something like what Apple does (taken from
>> <http://developer.apple.com/library/mac/#samplecode/Dicey/Listings/DCDie_m.html>):
>
> Yes, this is the approach I am suggesting.
>
> --Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden