Re: Are views active or inactive?

2009-12-23 Thread Gregory Weston
Rick Mann wrote:

 On Dec 22, 2009, at 19:51:03, Kyle Sluder wrote:
 
 On Tue, Dec 22, 2009 at 9:45 PM, Rick Mann rm...@latencyzero.com wrote:
 I'm listening for that notification. Sure is a clunky way to do things. 
 I've never used a view framework that didn't tell views when they became 
 active/inactive.
 
 Views don't become (in)active, windows do. Since there are plenty of
 things that might be interested in that (Window menu, controllers,
 views∑), it's done as a notification so all interested parties can
 listen for it.
 
 I'm not against the notification, I just think NSView should have an active 
 property. Views do become inactive (look at any well-designed control).

Did you happen to have an 'a-ha' moment when you typed that sentence? Views 
don't generally have an active/inactive state. Controls, which are a special 
case of view, do. So have you considered making your custom view an NSControl 
instead of a simple NSView?

That's the thing, you see. Inactive means the user can't interact with it. 
But the user can't interact with a view that's not a control anyway, so the 
state has no meaning.___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Jean-Daniel Dupas

Le 23 déc. 2009 à 12:06, Gregory Weston a écrit :

 Rick Mann wrote:
 
 On Dec 22, 2009, at 19:51:03, Kyle Sluder wrote:
 
 On Tue, Dec 22, 2009 at 9:45 PM, Rick Mann rm...@latencyzero.com wrote:
 I'm listening for that notification. Sure is a clunky way to do things. 
 I've never used a view framework that didn't tell views when they became 
 active/inactive.
 
 Views don't become (in)active, windows do. Since there are plenty of
 things that might be interested in that (Window menu, controllers,
 views∑), it's done as a notification so all interested parties can
 listen for it.
 
 I'm not against the notification, I just think NSView should have an active 
 property. Views do become inactive (look at any well-designed control).
 
 Did you happen to have an 'a-ha' moment when you typed that sentence? Views 
 don't generally have an active/inactive state. Controls, which are a special 
 case of view, do. So have you considered making your custom view an NSControl 
 instead of a simple NSView?
 
 That's the thing, you see. Inactive means the user can't interact with it. 
 But the user can't interact with a view that's not a control anyway, so the 
 state has no meaning.

and 'active' is called 'enabled' in Cocoa.


-- Jean-Daniel




___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Quincey Morris

On Dec 23, 2009, at 03:15, Jean-Daniel Dupas wrote:

 Le 23 déc. 2009 à 12:06, Gregory Weston a écrit :
 
 Rick Mann wrote:
 
 I'm not against the notification, I just think NSView should have an active 
 property. Views do become inactive (look at any well-designed control).
 
 Did you happen to have an 'a-ha' moment when you typed that sentence? 
 Views don't generally have an active/inactive state. Controls, which are a 
 special case of view, do. So have you considered making your custom view an 
 NSControl instead of a simple NSView?
 
 That's the thing, you see. Inactive means the user can't interact with it. 
 But the user can't interact with a view that's not a control anyway, so the 
 state has no meaning.
 
 and 'active' is called 'enabled' in Cocoa.

Except that it's more complicated than that, not entirely to Cocoa's glory.

The first responder in an active window loses what you might call focus when 
the window becomes inactive. It *also* by default loses the ability to respond 
to first mouse clicks, except when it doesn't (if the default behavior is 
overridden). 

If the view is a control, it may have an enabled-but-inactive appearance 
(usually, the color is removed or dimmed, such as the selection turning gray, 
or a NSTableView source list changing from blue to gray) that's different from 
their disabled appearance (disabled controls don't have selections at all). The 
appearance may or may not be matched to the first-responder/first-mouse-click 
state, but that's not consistent behavior nor is it enforced by the frameworks. 
And, of course, a control may be disabled in an active window for other 
reasons. And, of course, custom non-control views may choose to represent 
themselves differently in an inactive window, following the model (well, one of 
the models) provided by controls, or not.

There's no *formal* inactive state for views, although the state is often 
implemented informally, with greater or lesser consistency depending on the 
thoroughness of the developer and the state of advancement of the frameworks. 
(For example, IIRC the ability for a NSTableView to show a either visually 
inactive state or a disabled state is fairly recent.)

So, the answer is still that windows become inactive, but views (formally) do 
not. What views do (informally) is decided on a case-by-case basis.


___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Graham Cox

On 23/12/2009, at 10:15 PM, Jean-Daniel Dupas wrote:

 Did you happen to have an 'a-ha' moment when you typed that sentence? 
 Views don't generally have an active/inactive state. Controls, which are a 
 special case of view, do. So have you considered making your custom view an 
 NSControl instead of a simple NSView?
 
 That's the thing, you see. Inactive means the user can't interact with it. 
 But the user can't interact with a view that's not a control anyway, so the 
 state has no meaning.
 
 and 'active' is called 'enabled' in Cocoa.


Logically, enabled and active are two separate states - you can have a disabled 
control in an active window.

But, controls typically draw the same way if either of these are false (i.e. 
the 'disabled' appearance).

Views inherit the active state from their windows, so can ask their window for 
that state any time they need to know.

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

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


Re: Are views active or inactive?

2009-12-23 Thread Jean-Daniel Dupas

Le 23 déc. 2009 à 13:50, Graham Cox a écrit :

 
 On 23/12/2009, at 10:15 PM, Jean-Daniel Dupas wrote:
 
 Did you happen to have an 'a-ha' moment when you typed that sentence? 
 Views don't generally have an active/inactive state. Controls, which are 
 a special case of view, do. So have you considered making your custom view 
 an NSControl instead of a simple NSView?
 
 That's the thing, you see. Inactive means the user can't interact with 
 it. But the user can't interact with a view that's not a control anyway, so 
 the state has no meaning.
 
 and 'active' is called 'enabled' in Cocoa.
 
 
 Logically, enabled and active are two separate states - you can have a 
 disabled control in an active window.
 
 But, controls typically draw the same way if either of these are false (i.e. 
 the 'disabled' appearance).
 
 Views inherit the active state from their windows, so can ask their window 
 for that state any time they need to know.


My bad, sorry for the misunderstanding.

-- Jean-Daniel




___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Rick Mann

On Dec 23, 2009, at 03:06:58, Gregory Weston wrote:

 Did you happen to have an 'a-ha' moment when you typed that sentence? Views 
 don't generally have an active/inactive state. Controls, which are a special 
 case of view, do. So have you considered making your custom view an NSControl 
 instead of a simple NSView?
 
 That's the thing, you see. Inactive means the user can't interact with it. 
 But the user can't interact with a view that's not a control anyway, so the 
 state has no meaning.

On the contrary, users can interact with an inactive control. They can't 
interact with a disabled control. Consider a scroll bar. It can draw in an 
inactive state (not blue), but you can still interact with it by sending the 
window scroll events (something I'm unconvinced you should be able to do, but 
you can, and it proves convenient).

In my case, it's a drawing canvas. However, the active drawing tool should not 
draw when the view is inactive (not frontmost). Since the tool is a singleton 
object in the app used by many views, it's important to be able to make the 
distinction. I suppose I could subclass NSControl, but this strikes me as 
inelegant (and I don't know that it has active/inactive state anyway).

-- 
Rick

___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Rick Mann

On Dec 23, 2009, at 03:15:11, Jean-Daniel Dupas wrote:

 and 'active' is called 'enabled' in Cocoa.

Again, active and enabled are orthogonal properties.

-- 
Rick

___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Quincey Morris
On Dec 23, 2009, at 11:21, Rick Mann wrote:

 On Dec 23, 2009, at 03:15:11, Jean-Daniel Dupas wrote:
 
 and 'active' is called 'enabled' in Cocoa.
 
 Again, active and enabled are orthogonal properties.

Again, active isn't a *property* of views, or even of controls, for that 
matter.

For *some* Cocoa controls and views, there is an inactive *state* (as you 
noted, which typically involves suppressing color) that's displayed when the 
containing window is inactive. Every other representation of an inactive state 
in a NSView is implemented application by application, view by view, not in the 
frameworks.

In recent Mac OS releases, the HIGs having been moving towards demanding more 
consistent showing of inactive state in standard controls (and a few standard 
views).

But IIRC your original question was whether there's a standard mechanism that 
would directly cause a view to redraw itself when its window changed its 
active state, and answer is still no -- there are only indirect mechanisms 
(the view must in some sense observe the state of its window).

Incidentally, windows don't actually have an active state either. They have 
key and main states, whose representation is modified by the active state 
of the application.

As I said earlier in this thread, these states are complex, subtle, and to a 
degree historically jumbled.


___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Gregory Weston

On Dec 23, 2009, at 2:20 PM, Rick Mann wrote:

 
 On Dec 23, 2009, at 03:06:58, Gregory Weston wrote:
 
 Did you happen to have an 'a-ha' moment when you typed that sentence? 
 Views don't generally have an active/inactive state. Controls, which are a 
 special case of view, do. So have you considered making your custom view an 
 NSControl instead of a simple NSView?
 
 That's the thing, you see. Inactive means the user can't interact with it. 
 But the user can't interact with a view that's not a control anyway, so the 
 state has no meaning.
 
 On the contrary, users can interact with an inactive control. They can't 
 interact with a disabled control. Consider a scroll bar. It can draw in an 
 inactive state (not blue), but you can still interact with it by sending the 
 window scroll events (something I'm unconvinced you should be able to do, but 
 you can, and it proves convenient).

I'd point out that you've kind of gone off your own point here. Quibbling about 
what it means to interact with a control aside, you're still talking about a 
*control* having an inactive state, not a (generic) view.

 In my case, it's a drawing canvas. However, the active drawing tool should 
 not draw when the view is inactive (not frontmost). Since the tool is a 
 singleton object in the app used by many views, it's important to be able to 
 make the distinction. I suppose I could subclass NSControl, but this strikes 
 me as inelegant (and I don't know that it has active/inactive state anyway).

With this expanded explanation, I think the correct answer is that you're going 
about it the wrong way. It's not a normal Mac HI behavior for a drawing canvas 
to draw itself differently as a side-effect of its window being inactive.
___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Rick Mann

On Dec 23, 2009, at 13:26:11, Gregory Weston wrote:

 With this expanded explanation, I think the correct answer is that you're 
 going about it the wrong way. It's not a normal Mac HI behavior for a drawing 
 canvas to draw itself differently as a side-effect of its window being 
 inactive.

I would disagree. I think it is, and should be formalized in the architecture. 
That I can check if my view's parent window is the main window just reinforces 
the need to behave differently when active vs. inactive.

It's not elegant, which is why I think the notion should be formalized.

-- 
Rick

___

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

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


Re: Are views active or inactive?

2009-12-23 Thread Graham Cox

On 24/12/2009, at 8:26 AM, Gregory Weston wrote:

 With this expanded explanation, I think the correct answer is that you're 
 going about it the wrong way. It's not a normal Mac HI behavior for a drawing 
 canvas to draw itself differently as a side-effect of its window being 
 inactive.

Well, it depends.

Drawing canvases may or may not support the idea of a selection, and so 
highlight selected objects in a certain way. That highlight might want to be 
sensitive to the active state of the window so that it can be drawn using the 
inactive control colour when inactive rather than a bright highlight, or turned 
off altogether. Bright highlighting in inactive windows is distracting and 
misleading.

In DrawKit I do this, and the only way was to subscribe to the window's 
notifications for becoming/resigning main and refreshing the view.

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

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


Re: Are views active or inactive?

2009-12-23 Thread Rick Mann

On Dec 23, 2009, at 14:53:43, Graham Cox wrote:

 
 On 24/12/2009, at 8:26 AM, Gregory Weston wrote:
 
 With this expanded explanation, I think the correct answer is that you're 
 going about it the wrong way. It's not a normal Mac HI behavior for a 
 drawing canvas to draw itself differently as a side-effect of its window 
 being inactive.
 
 Well, it depends.
 
 Drawing canvases may or may not support the idea of a selection, and so 
 highlight selected objects in a certain way. That highlight might want to be 
 sensitive to the active state of the window so that it can be drawn using the 
 inactive control colour when inactive rather than a bright highlight, or 
 turned off altogether. Bright highlighting in inactive windows is distracting 
 and misleading.
 
 In DrawKit I do this, and the only way was to subscribe to the window's 
 notifications for becoming/resigning main and refreshing the view.


Thanks for confirming this is the way you do it. Helps reassure me it's a 
workable solution. Thanks again!___

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

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


Are views active or inactive?

2009-12-22 Thread Rick Mann
Hi. I realize this is a basic Cocoa question, but now that I need to know, I 
can't find the answer in the NSView or NSResponder docs.

Do NSViews have the notion of being active or inactive? My app architecture 
requires that I be able to differentiate, at draw time, between a (custom) view 
that is in the frontmost window (and technically, has focus), and a similar 
custom view that is in a non-frontmost window.

In my case, I have Tool objects (think of a line tool or rectangle tool in a 
drawing program). These are singleton objects in the app, and hence a line tool 
is shared among all document views. If the frontmost view is in the middle of a 
tool operation, and one of the inactive views updates its view, it shows the 
current tool drawing state (Tool objects get a chance to draw).

I'd like for my custom view to not give the Tool an opportunity to draw when it 
is not focussed/frontmost.

Thanks!

-- 
Rick

___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Kyle Sluder
On Tue, Dec 22, 2009 at 4:16 PM, Rick Mann rm...@latencyzero.com wrote:
 Do NSViews have the notion of being active or inactive? My app 
 architecture requires that I be able to differentiate, at draw time, between 
 a (custom) view that is in the frontmost window (and technically, has focus), 
 and a similar custom view that is in a non-frontmost window.

Listen for NSWindowDidBecomeMainNotification. -viewDidMoveToWindow is
a good time to start, and -viewWillMoveToWindow: is a good time to
stop.

--Kyle Sluder
___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Rick Mann

On Dec 22, 2009, at 19:41:06, Kyle Sluder wrote:

 On Tue, Dec 22, 2009 at 4:16 PM, Rick Mann rm...@latencyzero.com wrote:
 Do NSViews have the notion of being active or inactive? My app 
 architecture requires that I be able to differentiate, at draw time, between 
 a (custom) view that is in the frontmost window (and technically, has 
 focus), and a similar custom view that is in a non-frontmost window.
 
 Listen for NSWindowDidBecomeMainNotification. -viewDidMoveToWindow is
 a good time to start, and -viewWillMoveToWindow: is a good time to
 stop.

I'm listening for that notification. Sure is a clunky way to do things. I've 
never used a view framework that didn't tell views when they became 
active/inactive.

I'm not sure viewDidMoveToWindow works here. I'm using it already for something 
else, and it gets called 3 times when my window is created, but never when 
activated.

-- 
Rick


___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Jim Correia
On Dec 22, 2009, at 10:45 PM, Rick Mann wrote:

 I'm listening for that notification. Sure is a clunky way to do things. I've 
 never used a view framework that didn't tell views when they became 
 active/inactive.

AppKit views don’t have a native active/inactive status like carbon HIToolbox 
controls.

For views which alter their appearance based on whether or not they are first 
responder, or in a key/main window, you must track this state yourself.

 I'm not sure viewDidMoveToWindow works here. I'm using it already for 
 something else, and it gets called 3 times when my window is created, but 
 never when activated.

You can use viewWill/DidMoveToWindow to stop observing notifications on your 
preview window (if any) and start observing notifications on your new container 
window (if any), not for the tracking of the “active” state itself.

- Jim

___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Kyle Sluder
On Tue, Dec 22, 2009 at 9:45 PM, Rick Mann rm...@latencyzero.com wrote:
 I'm listening for that notification. Sure is a clunky way to do things. I've 
 never used a view framework that didn't tell views when they became 
 active/inactive.

Views don't become (in)active, windows do. Since there are plenty of
things that might be interested in that (Window menu, controllers,
views…), it's done as a notification so all interested parties can
listen for it.

 I'm not sure viewDidMoveToWindow works here. I'm using it already for 
 something else, and it gets called 3 times when my window is created, but 
 never when activated.

This surprises you? It's called -viewDidMoveToWindow after all. You
would start listening for all window change notifications there, and
then your view's notification handler would check to see if its window
is the one being notified about and update its drawing accordingly.

--Kyle Sluder
___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Rick Mann

On Dec 22, 2009, at 19:48:53, Jim Correia wrote:

 On Dec 22, 2009, at 10:45 PM, Rick Mann wrote:
 
 I'm listening for that notification. Sure is a clunky way to do things. I've 
 never used a view framework that didn't tell views when they became 
 active/inactive.
 
 AppKit views don’t have a native active/inactive status like carbon HIToolbox 
 controls.
 
 For views which alter their appearance based on whether or not they are first 
 responder, or in a key/main window, you must track this state yourself.

Dumb.

 
 I'm not sure viewDidMoveToWindow works here. I'm using it already for 
 something else, and it gets called 3 times when my window is created, but 
 never when activated.
 
 You can use viewWill/DidMoveToWindow to stop observing notifications on your 
 preview window (if any) and start observing notifications on your new 
 container window (if any), not for the tracking of the “active” state itself.

Problem still remains that it gets called 3 times. I just found out I was 
creating 3 tracking areas. Not sure if the willMoveToWindow is called in 
between.

-- 
Rick


___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Rick Mann

On Dec 22, 2009, at 19:51:03, Kyle Sluder wrote:

 On Tue, Dec 22, 2009 at 9:45 PM, Rick Mann rm...@latencyzero.com wrote:
 I'm listening for that notification. Sure is a clunky way to do things. I've 
 never used a view framework that didn't tell views when they became 
 active/inactive.
 
 Views don't become (in)active, windows do. Since there are plenty of
 things that might be interested in that (Window menu, controllers,
 views…), it's done as a notification so all interested parties can
 listen for it.

I'm not against the notification, I just think NSView should have an active 
property. Views do become inactive (look at any well-designed control).

___

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

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


Re: Are views active or inactive?

2009-12-22 Thread Joar Wingfors

On 22 dec 2009, at 19.45, Rick Mann wrote:

 Do NSViews have the notion of being active or inactive? My app 
 architecture requires that I be able to differentiate, at draw time, 
 between a (custom) view that is in the frontmost window (and technically, 
 has focus), and a similar custom view that is in a non-frontmost window.
 
 Listen for NSWindowDidBecomeMainNotification. -viewDidMoveToWindow is
 a good time to start, and -viewWillMoveToWindow: is a good time to
 stop.
 
 I'm listening for that notification. Sure is a clunky way to do things. I've 
 never used a view framework that didn't tell views when they became 
 active/inactive.


Lot's of interesting advice in this thread...   :-)

You don't have to listen to any notifications to achieve this. You will be 
asked to draw when the state of the window changes, and when you become or 
resign first responder status.

So, you don't have to figure out *when* to draw, but you do have to figure out 
*how* to draw.

Here are two things that you're often interested in taking into account:

* Is your window the key window

([NSApp keyWindow] == [self window])

* Are you the first responder of that window

([[self window] firstResponder] == self)

You can of course also track the state of these properties at all times using 
notifications and overrides of methods from your superclasses, but there is - 
like I said earlier - in general no need to.

j o a r


___

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

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