Re: PDFView focus ring

2012-02-04 Thread Martin Hewitson
Oh, and for the app losing focus, you can use: [NSApp isActive] to decide 
whether to draw the ring or not. Then in my app delegate I use 
-applicationWillResignActive: to trigger a redraw.

Martin

On 5, Feb, 2012, at 02:20 AM, Quincey Morris wrote:

> On Feb 4, 2012, at 16:17 , Graham Cox wrote:
> 
> 
> The one issue this doesn't solve is that of making room around the view to 
> draw the focus ring. If one or more edges of the view are flush with the edge 
> of the window, the exterior ring looks ugly.
> 
> In the past, I've sometimes taken the approach of drawing the focus ring 
> *inside* the view. (Use the view bounds rect, inset by 1.0, to draw the focus 
> ring, and don't lock focus on the superview, of course.) It looks pretty good 
> -- it's slightly transparent so it doesn't obscure the content much. However, 
> with this approach, there's apparently no way to take advantage of the spiffy 
> new Lion methods for focus rings. It's also less than ideal during an 
> inertial scroll "bounce".
> 
> 
> I think you also need to force an update when the app is deactivated. The 
> window is still the key window, but the focus ring shouldn't be drawn.
> 
> 


Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: martin.hewit...@aei.mpg.de
WWW: http://www.aei.mpg.de/~hewitson






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PDFView focus ring

2012-02-04 Thread Martin Hewitson
OK, I implemented Graham's solution and it works very well in my situation. The 
PDFView in question is not flush with any of the edges of a window, so I don't 
need to worry about that here. 

Thanks, Graham. Thanks, all!

Martin

On 5, Feb, 2012, at 02:20 AM, Quincey Morris wrote:

> On Feb 4, 2012, at 16:17 , Graham Cox wrote:
> 
>> The way I've done this is to handle the focus ring in the view's -drawRect 
>> method. You need to focus on the superview so you can draw outside your 
>> frame, but that's not a problem - just do it after you've drawn the rest of 
>> your normal content.
> 
> The one issue this doesn't solve is that of making room around the view to 
> draw the focus ring. If one or more edges of the view are flush with the edge 
> of the window, the exterior ring looks ugly.
> 
> In the past, I've sometimes taken the approach of drawing the focus ring 
> *inside* the view. (Use the view bounds rect, inset by 1.0, to draw the focus 
> ring, and don't lock focus on the superview, of course.) It looks pretty good 
> -- it's slightly transparent so it doesn't obscure the content much. However, 
> with this approach, there's apparently no way to take advantage of the spiffy 
> new Lion methods for focus rings. It's also less than ideal during an 
> inertial scroll "bounce".
> 
>> The only other thing I've found necessary is to track whether the focus ring 
>> needs an update or not by using 
>> -setKeyboardFocusRingNeedsDisplayInRect:[self bounds] which I call from 
>> -becomeFirstResponder and -resignFirstResponder.
> 
> I think you also need to force an update when the app is deactivated. The 
> window is still the key window, but the focus ring shouldn't be drawn.
> 
> 






___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PDFView focus ring

2012-02-04 Thread Graham Cox

On 05/02/2012, at 12:20 PM, Quincey Morris wrote:

> The one issue this doesn't solve is that of making room around the view to 
> draw the focus ring. If one or more edges of the view are flush with the edge 
> of the window, the exterior ring looks ugly.


True, though if all edges are flush with the window, or an enclosing 
scrollview, it's not visible at all. The views I've done this for don't work 
that way so I didn't address the problem. I imagine the reason many views leave 
the whole focus ring drawing to you is that there is no single solution for 
whether it's drawing inside or outside.

> I think you also need to force an update when the app is deactivated. The 
> window is still the key window, but the focus ring shouldn't be drawn.

What I usually do is have an 'active' state that is ANDed with the focus being 
true to determine whether to draw the ring. Then the focus ring goes away 
whenever inactive, including when the window isn't key but the app is still 
active. Usually other elements in the view would also be interested in that 
state (even if only to use a grey highlight instead of colour, for example). Of 
course you have to add additional code to make that refresh happen when the 
active state changes.

--Graham




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PDFView focus ring

2012-02-04 Thread Quincey Morris
On Feb 4, 2012, at 16:17 , Graham Cox wrote:

> The way I've done this is to handle the focus ring in the view's -drawRect 
> method. You need to focus on the superview so you can draw outside your 
> frame, but that's not a problem - just do it after you've drawn the rest of 
> your normal content.

The one issue this doesn't solve is that of making room around the view to draw 
the focus ring. If one or more edges of the view are flush with the edge of the 
window, the exterior ring looks ugly.

In the past, I've sometimes taken the approach of drawing the focus ring 
*inside* the view. (Use the view bounds rect, inset by 1.0, to draw the focus 
ring, and don't lock focus on the superview, of course.) It looks pretty good 
-- it's slightly transparent so it doesn't obscure the content much. However, 
with this approach, there's apparently no way to take advantage of the spiffy 
new Lion methods for focus rings. It's also less than ideal during an inertial 
scroll "bounce".

> The only other thing I've found necessary is to track whether the focus ring 
> needs an update or not by using -setKeyboardFocusRingNeedsDisplayInRect:[self 
> bounds] which I call from -becomeFirstResponder and -resignFirstResponder.

I think you also need to force an update when the app is deactivated. The 
window is still the key window, but the focus ring shouldn't be drawn.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PDFView focus ring

2012-02-04 Thread Graham Cox

On 04/02/2012, at 8:06 PM, Martin Hewitson wrote:

> Thank you all for your responses. I need to support 10.6.8, so in end I chose 
> two different approaches for the textview and pdfview.
> 
> For the textview, I handle drawing a thin rect around the textview's bounds 
> when it is first responder. I just handle the change in 
> -becomeFirstResponder and -resignFirstResponder.
> 
> For the pdfview, I embedded it in an NSView which receives notifications when 
> the pdfview becomes or resigns first responder. Then it draws a thin rect 
> around its bounds. The pdfview is then 1 pixel smaller on all sides that this 
> container view.
> 
> I'm not really happy with either of these solutions, but nothing else seemed 
> to work so far. The end result is visually not too bad. The thing I like 
> least is that I need this 1 pixel gap in the container view for the pdfview. 
> Because when the pdfview doesn't have focus, I have to decide to draw 
> something there. For now I toggle between stroke colors (dark grey and focus 
> ring color).


Sounds pretty complicated.

The way I've done this is to handle the focus ring in the view's -drawRect 
method. You need to focus on the superview so you can draw outside your frame, 
but that's not a problem - just do it after you've drawn the rest of your 
normal content. You can detect whether the view has the keyboard focus by using:

[[self window] firstResponder] == self;

The code to draw the focus ring doesn't need to outset the frame by any amount 
- the special case of -fill that uses the focus ring style manages that trick 
for you, so the code is:

// we have the focus, draw the focus ring and use appropriate 
active colours

[[self superview] lockFocus];
NSRect fr = [self frame];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect:fr] fill];
[[self superview] unlockFocus];


The only other thing I've found necessary is to track whether the focus ring 
needs an update or not by using -setKeyboardFocusRingNeedsDisplayInRect:[self 
bounds] which I call from -becomeFirstResponder and -resignFirstResponder.

I'm not sure if this is considered the "correct" way to do all that (in 
pre-Lion code), but it has always worked well for me, and the advantage of it 
is that it doesn't require that you have any special outer view to support the 
focus ring.

--Graham



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PDFView focus ring

2012-02-04 Thread Martin Hewitson
Thank you all for your responses. I need to support 10.6.8, so in end I chose 
two different approaches for the textview and pdfview.

For the textview, I handle drawing a thin rect around the textview's bounds 
when it is first responder. I just handle the change in 
-becomeFirstResponder and -resignFirstResponder.

For the pdfview, I embedded it in an NSView which receives notifications when 
the pdfview becomes or resigns first responder. Then it draws a thin rect 
around its bounds. The pdfview is then 1 pixel smaller on all sides that this 
container view.

I'm not really happy with either of these solutions, but nothing else seemed to 
work so far. The end result is visually not too bad. The thing I like least is 
that I need this 1 pixel gap in the container view for the pdfview. Because 
when the pdfview doesn't have focus, I have to decide to draw something there. 
For now I toggle between stroke colors (dark grey and focus ring color).

Cheers,

Martin


On 2, Feb, 2012, at 05:34 PM, Sean McBride wrote:

> On Thu, 2 Feb 2012 09:05:14 +1100, Graham Cox said:
> 
>> Some views don't actually implement a focus ring, leaving it to you.
>> This is often the case if the view is typically used for content within
>> a scrollview. Bear in mind also that the focus ring is drawn outside the
>> frame of the view, so there has to be a) space available to draw it, and
>> b) code there to do that drawing outside the view. These are things you
>> might want to check. If necessary, you may have to subclass the view and
>> add the focus ring yourself.
> 
> In 10.7, there is new API to make focus ring drawing easier.  See:
> 
> 
> 
> I've been experimenting with it, and it works great, though I have seen it 
> frequently appear as an offender when profiling with Instruments.
> 
> --
> 
> Sean McBride, B. Eng s...@rogue-research.com
> Rogue Researchwww.rogue-research.com
> Mac Software Developer  Montréal, Québec, Canada
> 
> 


Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer 
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: martin.hewit...@aei.mpg.de
WWW: http://www.aei.mpg.de/~hewitson







___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: PDFView focus ring

2012-02-02 Thread Sean McBride
On Thu, 2 Feb 2012 09:05:14 +1100, Graham Cox said:

>Some views don't actually implement a focus ring, leaving it to you.
>This is often the case if the view is typically used for content within
>a scrollview. Bear in mind also that the focus ring is drawn outside the
>frame of the view, so there has to be a) space available to draw it, and
>b) code there to do that drawing outside the view. These are things you
>might want to check. If necessary, you may have to subclass the view and
>add the focus ring yourself.

In 10.7, there is new API to make focus ring drawing easier.  See:



I've been experimenting with it, and it works great, though I have seen it 
frequently appear as an offender when profiling with Instruments.  

-- 

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com 
Mac Software Developer  Montréal, Québec, Canada



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: PDFView focus ring

2012-02-01 Thread Graham Cox
Hi Martin,

Some views don't actually implement a focus ring, leaving it to you. This is 
often the case if the view is typically used for content within a scrollview. 
Bear in mind also that the focus ring is drawn outside the frame of the view, 
so there has to be a) space available to draw it, and b) code there to do that 
drawing outside the view. These are things you might want to check. If 
necessary, you may have to subclass the view and add the focus ring yourself.

--Graham


On 01/02/2012, at 6:19 PM, Martin Hewitson wrote:

> Dear list,
> 
> This is perhaps a silly question, but I can't find the answer anywhere. I 
> have an app which has an editor on the left side of a splitview and a pdfview 
> on the right side of the splitview. Then I have a keyboard shortcut to toggle 
> focus between the editor and the pdfview. The problem is that the pdfview 
> doesn't show a focus ring, so it's very hard for the user to see that the 
> focus changed. Does anyone know a way that I can make the pdfview show a 
> focus ring? I have tried setting it to Default and Exterior in IB, but it 
> still doesn't appear.
> 
> Best wishes,
> 
> Martin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: PDFView focus ring

2012-02-01 Thread Joel Norvell
Hi Martin,

This is just a guess.

Could the NSFocusRingType set in IB be overridden somehow for the PDFView?

You might explicitly test the focusRingType to see what it is once it's been 
created.

Sincerely,
Joel


Martin Hewitson wrote:

... I have an app which has an editor on the left side of a splitview and a 
pdfview on the right side of the splitview. Then I have a keyboard shortcut to 
toggle focus between the editor and the pdfview. The problem is that the 
pdfview doesn't show a focus ring, so it's very hard for the user to see that 
the focus changed. Does anyone know a way that I can make the pdfview show a 
focus ring? I have tried setting it to Default and Exterior in IB, but it still 
doesn't appear.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


PDFView focus ring

2012-01-31 Thread Martin Hewitson
Dear list,

This is perhaps a silly question, but I can't find the answer anywhere. I have 
an app which has an editor on the left side of a splitview and a pdfview on the 
right side of the splitview. Then I have a keyboard shortcut to toggle focus 
between the editor and the pdfview. The problem is that the pdfview doesn't 
show a focus ring, so it's very hard for the user to see that the focus 
changed. Does anyone know a way that I can make the pdfview show a focus ring? 
I have tried setting it to Default and Exterior in IB, but it still doesn't 
appear.

Best wishes,

Martin
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com