On Jul 28, 2008, at 3:29 PM, R.L. Grigg wrote:


On Jul 26, 2008, at 3:15 AM, Michael Ash wrote:

On Fri, Jul 25, 2008 at 11:08 PM, Henry McGilton (Starbase)
<[EMAIL PROTECTED]> wrote:
On Jul 25, 2008, at 6:50 PM, Michael Ash wrote:

In fact I would go so far as to say that if you ever use
-setContentView:, you are very probably doing it wrong. It is, for the
most part, not a very useful call, and you can accomplish the same
thing more naturally, easily, and flexibly by adding the view as a
subview to the content view instead.

Well, I would not go quite that far, although I agree with you
in principle for normal everyday stuff.    I have some applications
which create bare windows --- no borders, controls, resizers,
shadows, and so on.    The view that replaces the default window
content view does all the drawing.    I don't see any value in
having a content view whose only purpose in life is to act as
a container for my drawing view.

Might come a day that you want two views in there, or you want to move
that one view around, and suddenly the value appears. Since it's no
harder to do things the "right" way, why not?

Okay, I'm a little bit confused. What is the "right" way?

I create a NSWindow and then I'm displaying a NSMatrix in that window. Now I need to move the NSMatrix around in the NSWindow.

Is something like this a decent Cocoa approach:

   // create the window
   myWindow = [[NSWindow alloc] initWithContentRect: ... ];
   // insert the existing matrix as it's content view
   [myWindow setContentView:myMatrix];
   // alter the position of the matrix
   NSPoint newPoint = ...
   [myMatrix setFrameOrigin:newPoint];
   [myWindow display];

Thx!
Russ

Hey Russ -

The location and size of the content view of the window is conceptually owned by the NSWindow instance. If you alter the origin, you're breaking the encapsulation provided by NSWindow and the NSWindow is likely to either break, or reset it, or both. You should leave the content view of the window in its default state as a vanilla NSView, and instead add your matrix to the window's content view. You can do that with something like this:

   myWindow = [[NSWindow alloc] initWithContentRect: ... ];
   // insert the existing matrix as it's content view
   [[myWindow contentView] addSubview:myMatrix];
   // alter the position of the matrix
   NSPoint newPoint = ...
   [myMatrix setFrameOrigin:newPoint];

I also removed the call to [myWindow display]. You should only ever call 'display' or 'displayIfNeeded' if you have a good reason to short circuit the normal view/window redrawing mechanism. Short circuiting the behavior can lead to poor performance if the window ends up accidently being drawn many times per event loop.

Good Luck -
Jon Hess




_______________________________________________

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/jhess%40apple.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to