Re: Initializing NSWindow with Carbon window
Re: Initializing NSWindow with Carbon window
- Subject: Re: Initializing NSWindow with Carbon window
- From: Andrew James <email@hidden>
- Date: Sun, 30 Jan 2011 23:45:07 -0800 (PST)
I've done some investigating and still getting the behavior that the window does
not display from the code below
Interestingly, if you look at the two ShowWindow/SelectWindow pairs. I will see
the window when the first one is uncommented only. I will not see the window
when the second set is uncommented only. ODD. Don't know if this provides any
insight.
WindowRef carbonWindow = carbonBuilder.GetProduct();
// If these are only Show/Select uncommented, window will display
//ShowWindow( carbonWindow );
//SelectWindow( carbonWindow );
NSWindow *wrapper = [ [ NSWindow alloc ] initWithWindowRef: carbonWindow ];
// If these are only Show/Select uncommented, window will NOT display
//ShowWindow( carbonWindow );
//SelectWindow( carbonWindow );
NSLog( @"Window frame = %@", NSStringFromRect( [ wrapper frame ] ) );
NSLog( @"Window content frame = %@", NSStringFromRect( [ [ wrapper contentView ]
frame ] ) );
NSLog( @"Window alpha value = %f", [ wrapper alphaValue ] );
NSLog( @"Window visibility = %d", [ wrapper isVisible ] );
NSLog( @"Carbon window visibility = %d", IsWindowVisible( carbonWindow ) );
[ wrapper makeKeyAndOrderFront: self];
NSLog( @"Window frame = %@", NSStringFromRect( [ wrapper frame ] ) );
NSLog( @"Window content frame = %@", NSStringFromRect( [ [ wrapper contentView ]
frame ] ) );
NSLog( @"Window alpha value = %f", [ wrapper alphaValue ] );
NSLog( @"Window visibility = %d", [ wrapper isVisible ] );
NSLog( @"Carbon window visibility = %d", IsWindowVisible( carbonWindow ) );
Here's the output I see:
2011-01-30 23:41:28.379 Empath[1126:a0f] Window frame = {{599, 246}, {776, 687}}
2011-01-30 23:41:28.381 Empath[1126:a0f] Window content frame = {{12, 0}, {764,
687}}
2011-01-30 23:41:28.381 Empath[1126:a0f] Window alpha value = 1.000000
2011-01-30 23:41:28.382 Empath[1126:a0f] Window visibility = 0
2011-01-30 23:41:28.382 Empath[1126:a0f] Carbon window visibility = 0
2011-01-30 23:41:28.386 Empath[1126:a0f] Window frame = {{599, 246}, {776, 687}}
2011-01-30 23:41:28.386 Empath[1126:a0f] Window content frame = {{12, 0}, {764,
687}}
2011-01-30 23:41:28.387 Empath[1126:a0f] Window alpha value = 1.000000
2011-01-30 23:41:28.387 Empath[1126:a0f] Window visibility = 1
2011-01-30 23:41:28.387 Empath[1126:a0f] Carbon window visibility = 1
But as I've said... still no window. Hrmm.
I should say, that the end goal is to be able to have this NSWindow owned by an
NSWindowController. The reasoning for this is that I have a factory method that
returns an NSWindowController.
I'd rather not back down from this and write my own class that does the
controlling of Cocoa vs. Carbon windows.
--aj
----- Original Message ----
From: Graham Cox <email@hidden>
To: Andrew James <email@hidden>
Cc: list-cocoa-dev <email@hidden>
Sent: Sun, January 30, 2011 8:18:23 PM
Subject: Re: Initializing NSWindow with Carbon window
On 31/01/2011, at 3:02 PM, Andrew James wrote:
> For once I actually should have "cut-and-paste":
>
> NSWindow *wrapper = [ [ NSWindow alloc ] initWithWindowRef:
> carbonBuilder.GetProduct() ];
> [ wrapper makeKeyAndOrderFront: self];
>
> I did have the sender being sent correctly. Window still does not show with
> this approach. Nice catch though.
>
> I'm going to keep trying. Going to see if makeKeyAndOrderFront is causing any
> Carbon Events to be generated for the wrapped window.
>
> I may also take the route of subclassing NSWindowController with something like
>
>
> WrappedCarbonWindowController and look into subclassing methods like
>showWindow.
>
> Implementing a window delegate my also help. I've got options that I'm going
> to explore.
There are some simpler things to try first.
Does carbonBuilder.GetProduct() actually return anything?
Is the <wrapper> variable set to something after creating the window?
If yes to both, try looking at properties of <wrapper>, such as its frame. That
will tell you if it's actually supposed to be on the screen.
If the window object isn't created, it might be that the carbon window type
and/or combination of flags isn't supported, so you may have to go back and
modify the carbon window you return to something currently legal. (I'm guessing
here, I haven't had cause to do this myself, but AFAIK -initWithWindowRef: is
not broken).
Adding a window delegate isn't required to show a window, and adding one is only
going to complicate matters at this stage. Also, I don't know that carbon events
are generated even if NSWindow was inited with a carbon window.
--Graham
_______________________________________________
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