Re: Dragging Transparent NSWindow with parent NSOpenGLView

Christiaan Hofman <[email protected]> Fri, 2 Jul 2010 11:01:55 +0200
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
On Jul 2, 2010, at 8:28, NickMtl wrote:

> OK, here's the code I use to allocate the SearchField's window:
> 
>    // Allocate SearchFieldWindow Controller
>    if ( [SearchFieldWindowController
> sharedSearchFieldWindowController] == nil ) // allocate and show
>    {
> 	[SearchFieldWindowController allocSharedSearchFieldWindowController];
> 	if ( [SearchFieldWindowController sharedSearchFieldWindowController] == nil )
> 	{
> 	    wcout << L"Failed to allocate search field";
> 	    return;
> 	}
> 	
> 	// Add as child window -- so they move together -- FAILED
> 	NSWindow*	    nsMainWindow	    = [[AppController getAppController]
> getMainWindow];
> 	SearchFieldWindow*  nsSearchFieldWindow	    =
> [[SearchFieldWindowController sharedSearchFieldWindowController]
> getWindow];
> 	[nsMainWindow	    addChildWindow:nsSearchFieldWindow ordered:NSWindowAbove];
> 	
> 	[[SearchFieldWindowController sharedSearchFieldWindowController]
> showWindow:nil];
> 	
> 	// Resize Text view
> 	[[SearchFieldWindowController sharedSearchFieldWindowController]
> resizeSearchFieldWindow];
> 	
>    }
> 

This should work from what I can see, though of course there can be happening all kinds of wrong stuff inside your custom methods you call, if things fail it probably is in all the code you did not show. 

And you did not say exactly how it failed.

You may take a look at the code we're using for overlay windows (which can even be placed covering particular views) <http://bibdesk.svn.sourceforge.net/viewvc/bibdesk/trunk/bibdesk/BDSKOverlayWindow.m?view=markup>.

Some OT remarks about style: you're using the wrong method names for Cocoa. You should (almost) never use "get" for getters, and methods starting with "alloc" are also supposed to be special (see memory management rules in Objective-C), I am sure you are not complying in this method, and if you are you're (technically) leaking (clang will certainly give you warnings). Also, you should always start your class names with a custom prefix.

Christiaan

> 
>> Hrm? This is precisely the situation child windows are designed for.
>> We use them all over the place to keep overlays on top of windows as
>> they are dragged about.
>> 
>> You'll need to post your code. Maybe you set up the relationship in
>> the wrong direction?
>> 
>> Also, *please* do not autorespond to list postings. And it's
>> beneficial to keep discussions on-list, for the benefit of the
>> archives.
>> 
>> --Kyle Sluder