Index: Examples/GUI/Cocoa/BasicVTKView.mm =================================================================== RCS file: /cvsroot/VTK/VTK/Examples/GUI/Cocoa/BasicVTKView.mm,v retrieving revision 1.5 diff -u -r1.5 BasicVTKView.mm --- Examples/GUI/Cocoa/BasicVTKView.mm 14 Dec 2007 21:41:51 -0000 1.5 +++ Examples/GUI/Cocoa/BasicVTKView.mm 10 Feb 2009 16:13:38 -0000 @@ -57,28 +57,32 @@ vtkRenderWindow* renWin = vtkRenderWindow::New(); vtkRenderWindowInteractor* renWinInt = vtkRenderWindowInteractor::New(); - // This is special to our usage of vtk. To prevent vtk - // from creating an NSWindow and NSView automatically (its - // default behaviour) we tell vtk that they exist already. - // The APIs names are a bit misleading, due to the cross - // platform nature of vtk, but this usage is correct. - renWin->SetWindowId([self window]); - renWin->SetDisplayId(self); - - // The usual vtk connections - renWin->AddRenderer(ren); - renWinInt->SetRenderWindow(renWin); - - // This is special to our usage of vtk. vtkCocoaGLView - // keeps track of the renderWindow, and has a get - // accessor if you ever need it. // The cast should never fail, but we do it anyway, as // it's more correct to do so. vtkCocoaRenderWindow* cocoaRenWin = vtkCocoaRenderWindow::SafeDownCast(renWin); - [self setVTKRenderWindow:cocoaRenWin]; + + if (ren && cocoaRenWin && renWinInt) + { + // This is special to our usage of vtk. To prevent vtk + // from creating an NSWindow and NSView automatically (its + // default behaviour) we tell vtk that they exist already. + // The APIs names are a bit misleading, due to the cross + // platform nature of vtk, but this usage is correct. + cocoaRenWin->SetRootWindow([self window]); + cocoaRenWin->SetWindowId(self); - // Likewise, BasicVTKView keeps track of the renderer - [self setRenderer:ren]; + // The usual vtk connections + cocoaRenWin->AddRenderer(ren); + renWinInt->SetRenderWindow(cocoaRenWin); + + // This is special to our usage of vtk. vtkCocoaGLView + // keeps track of the renderWindow, and has a get + // accessor if you ever need it. + [self setVTKRenderWindow:cocoaRenWin]; + + // Likewise, BasicVTKView keeps track of the renderer + [self setRenderer:ren]; + } } - (void)cleanUpVTKSupport Index: Rendering/vtkCocoaRenderWindow.h =================================================================== RCS file: /cvsroot/VTK/VTK/Rendering/vtkCocoaRenderWindow.h,v retrieving revision 1.39 diff -u -r1.39 vtkCocoaRenderWindow.h --- Rendering/vtkCocoaRenderWindow.h 22 Jan 2009 16:57:53 -0000 1.39 +++ Rendering/vtkCocoaRenderWindow.h 10 Feb 2009 16:13:42 -0000 @@ -25,8 +25,8 @@ // Cocoa APIs. This class's default behaviour is to create an NSWindow and // a vtkCocoaGLView which are used together to draw all vtk stuff into. // If you already have an NSWindow and vtkCocoaGLView and you want this -// class to use them you must call both SetWindowId() and SetDisplayId() -// early on (before WindowInitialize() is executed). +// class to use them you must call both SetRootWindow() and SetWindowId(), +// respectively, early on (before WindowInitialize() is executed). // // .SECTION See Also // vtkOpenGLRenderWindow vtkCocoaGLView @@ -125,6 +125,15 @@ vtkWarningMacro("Method not implemented."); return 0; } + virtual void SetDisplayId(void*) + { + vtkWarningMacro("Method not implemented."); + } + virtual void *GetGenericDisplayId() + { + vtkWarningMacro("Method not implemented."); + return 0; + } // Description: // Set this RenderWindow's window id to a pre-existing window. @@ -232,33 +241,32 @@ // Description: // Sets the NSWindow* associated with this vtkRenderWindow. This class' default - // behaviour, that is, if you never call this SetDisplayId()/SetWindowId() is + // behaviour, that is, if you never call SetWindowId()/SetRootWindow() is // to create an NSWindow and a vtkCocoaGLView (NSView subclass) which are used // together to draw all vtk stuff into. If you already have an NSWindow and - // NSView and you want this class to use them you must call both SetWindowId() - // and SetDisplayId() early on (before WindowInitialize() is executed). In the - // case of Java, you should call only SetDisplayId(). - virtual void SetWindowId(void *); + // NSView and you want this class to use them you must call both SetRootWindow() + // and SetWindowId(), respectively, early on (before WindowInitialize() is + // executed). In the case of Java, you should call only SetWindowId(). + virtual void SetRootWindow(void *); // Description: // Returns the NSWindow* associated with this vtkRenderWindow. - virtual void *GetWindowId(); - virtual void *GetGenericWindowId() {return this->GetWindowId();} + virtual void *GetRootWindow(); // Description: // Sets the NSView* associated with this vtkRenderWindow. This class' default - // behaviour, that is, if you never call this SetDisplayId()/SetWindowId() is + // behaviour, that is, if you never call this SetWindowId()/SetRootWindow() is // to create an NSWindow and a vtkCocoaGLView (NSView subclass) which are used // together to draw all vtk stuff into. If you already have an NSWindow and - // NSView and you want this class to use them you must call both SetWindowId() - // and SetDisplayId() early on (before WindowInitialize() is executed). In the - // case of Java, you should call only SetDisplayId(). - virtual void SetDisplayId(void *); + // NSView and you want this class to use them you must call both SetRootWindow() + // and SetWindowId(), respectively, early on (before WindowInitialize() is + // executed). In the case of Java, you should call only SetWindowId(). + virtual void SetWindowId(void *); // Description: // Returns the NSView* associated with this vtkRenderWindow. - virtual void *GetDisplayId(); - virtual void *GetGenericDisplayId() {return this->GetDisplayId();} + virtual void *GetWindowId(); + virtual void *GetGenericWindowId() {return this->GetWindowId();} // Description: // Returns the scaling factor for 'resolution independence', to convert Index: Rendering/vtkCocoaRenderWindow.mm =================================================================== RCS file: /cvsroot/VTK/VTK/Rendering/vtkCocoaRenderWindow.mm,v retrieving revision 1.65 diff -u -r1.65 vtkCocoaRenderWindow.mm --- Rendering/vtkCocoaRenderWindow.mm 22 Jan 2009 17:45:37 -0000 1.65 +++ Rendering/vtkCocoaRenderWindow.mm 10 Feb 2009 16:13:42 -0000 @@ -138,15 +138,15 @@ this->SetPixelFormat(NULL); } - this->SetDisplayId(NULL); this->SetWindowId(NULL); + this->SetRootWindow(NULL); } //---------------------------------------------------------------------------- void vtkCocoaRenderWindow::SetWindowName( const char * _arg ) { vtkWindow::SetWindowName(_arg); - if (this->GetWindowId()) + if (this->GetRootWindow()) { NSString* winTitleStr; @@ -156,7 +156,7 @@ winTitleStr = [NSString stringWithCString:_arg]; #endif - [(NSWindow*)this->GetWindowId() setTitle:winTitleStr]; + [(NSWindow*)this->GetRootWindow() setTitle:winTitleStr]; } } @@ -327,14 +327,14 @@ this->Modified(); this->Size[0] = x; this->Size[1] = y; - if (this->GetWindowId() && this->Mapped) + if (this->GetRootWindow() && this->Mapped) { if (!resizing) { resizing = 1; // VTK measures in pixels, but NSWindow/NSView measure in points; convert. NSSize theSize = NSMakeSize((CGFloat)x / this->ScaleFactor, (CGFloat)y / this->ScaleFactor); - [(NSWindow*)this->GetWindowId() setContentSize:theSize]; + [(NSWindow*)this->GetRootWindow() setContentSize:theSize]; resizing = 0; } } @@ -363,13 +363,13 @@ this->Modified(); this->Position[0] = x; this->Position[1] = y; - if (this->GetWindowId() && this->Mapped) + if (this->GetRootWindow() && this->Mapped) { if (!resizing) { resizing = 1; NSPoint origin = NSMakePoint((CGFloat)x, (CGFloat)y); - [(NSWindow*)this->GetWindowId() setFrameOrigin:origin]; + [(NSWindow*)this->GetRootWindow() setFrameOrigin:origin]; resizing = 0; } } @@ -497,8 +497,8 @@ // create an NSWindow only if neither an NSView nor an NSWindow have // been specified already. This is the case for a 'pure vtk application'. // If you are using vtk in a 'regular Mac application' you should call - // SetWindowId() and SetDisplayId() so that a window is not created. - if (!this->GetWindowId() && !this->GetDisplayId()) + // SetRootWindow() and SetWindowId() so that a window is not created here. + if (!this->GetRootWindow() && !this->GetWindowId()) { if ((this->Size[0]+this->Size[1]) == 0) { @@ -532,30 +532,30 @@ [theWindow setAcceptsMouseMovedEvents:YES]; - this->SetWindowId(theWindow); + this->SetRootWindow(theWindow); this->WindowCreated = 1; } // Always use the scaling factor from the window once it is created. // The screen and the window might possibly have different scaling factors, though unlikely. #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1040 - if (this->GetWindowId()) + if (this->GetRootWindow()) { - this->ScaleFactor = [(NSWindow*)this->GetWindowId() userSpaceScaleFactor]; + this->ScaleFactor = [(NSWindow*)this->GetRootWindow() userSpaceScaleFactor]; } #endif // create a vtkCocoaGLView if one has not been specified - if (!this->GetDisplayId()) + if (!this->GetWindowId()) { // VTK measures in pixels, but NSWindow/NSView measure in points; convert. NSRect glRect = NSMakeRect(0.0, 0.0, (CGFloat)this->Size[0] / this->ScaleFactor, (CGFloat)this->Size[1] / this->ScaleFactor); vtkCocoaGLView *glView = [[[vtkCocoaGLView alloc] initWithFrame:glRect] autorelease]; - [(NSWindow*)this->GetWindowId() setContentView:glView]; + [(NSWindow*)this->GetRootWindow() setContentView:glView]; - this->SetDisplayId(glView); + this->SetWindowId(glView); this->ViewCreated = 1; [glView setVTKRenderWindow:this]; } @@ -586,7 +586,7 @@ // IMPORTANT: this is necessary to update the context here in case of // hardware offscreen rendering NSOpenGLContext* context = (NSOpenGLContext*)this->GetContextId(); - [context setView:(NSView*)this->GetDisplayId()]; + [context setView:(NSView*)this->GetWindowId()]; [context update]; @@ -680,7 +680,7 @@ // IMPORTANT: this is necessary to update the context here in case of // onscreen rendering NSOpenGLContext* context = (NSOpenGLContext*)this->GetContextId(); - [context setView:(NSView*)this->GetDisplayId()]; + [context setView:(NSView*)this->GetWindowId()]; [context update]; } @@ -714,7 +714,7 @@ // is overloaded. It's really the NSView that vtk draws into, so we // return its size. // VTK measures in pixels, but NSWindow/NSView measure in points; convert. - NSRect frameRect = [(NSView*)this->GetDisplayId() frame]; + NSRect frameRect = [(NSView*)this->GetWindowId() frame]; this->Size[0] = (int)round(NSWidth(frameRect) * this->ScaleFactor); this->Size[1] = (int)round(NSHeight(frameRect) * this->ScaleFactor); return this->Superclass::GetSize(); @@ -756,7 +756,7 @@ // is overloaded. In this case, it's the position of the NSWindow itself // on the screen that we return. We don't much care where the NSView is // within the NSWindow. - NSRect winFrameRect = [(NSWindow*)this->GetWindowId() frame]; + NSRect winFrameRect = [(NSWindow*)this->GetRootWindow() frame]; this->Position[0] = (int)NSMinX(winFrameRect); this->Position[1] = (int)NSMinY(winFrameRect); return this->Position; @@ -792,7 +792,7 @@ else { // if window already up get its values - if (this->GetWindowId()) + if (this->GetRootWindow()) { pos = this->GetPosition(); this->OldScreen[0] = pos[0]; @@ -854,8 +854,8 @@ os << indent << "MultiSamples: " << this->MultiSamples << "\n"; os << indent << "ScaleFactor: " << this->GetScaleFactor() << "\n"; os << indent << "CocoaManager: " << this->GetCocoaManager() << "\n"; + os << indent << "RootWindow: " << this->GetRootWindow() << "\n"; os << indent << "WindowId: " << this->GetWindowId() << "\n"; - os << indent << "DisplayId: " << this->GetDisplayId() << "\n"; os << indent << "ContextId: " << this->GetContextId() << "\n"; os << indent << "PixelFormat: " << this->GetPixelFormat() << "\n"; os << indent << "WindowCreated: " << (this->WindowCreated ? "Yes" : "No") << "\n"; @@ -882,57 +882,57 @@ //---------------------------------------------------------------------------- // Returns the NSWindow* associated with this vtkRenderWindow. -void *vtkCocoaRenderWindow::GetWindowId() +void *vtkCocoaRenderWindow::GetRootWindow() { NSMutableDictionary* manager = reinterpret_cast(this->GetCocoaManager()); - return reinterpret_cast([manager objectForKey:@"WindowId"]); + return reinterpret_cast([manager objectForKey:@"RootWindow"]); } //---------------------------------------------------------------------------- // Sets the NSWindow* associated with this vtkRenderWindow. -void vtkCocoaRenderWindow::SetWindowId(void *arg) +void vtkCocoaRenderWindow::SetRootWindow(void *arg) { if (arg != NULL) { NSMutableDictionary* manager = reinterpret_cast(this->GetCocoaManager()); [manager setObject:reinterpret_cast(arg) - forKey:@"WindowId"]; + forKey:@"RootWindow"]; } else { NSMutableDictionary* manager = reinterpret_cast(this->GetCocoaManager()); - [manager removeObjectForKey:@"WindowId"]; + [manager removeObjectForKey:@"RootWindow"]; } } //---------------------------------------------------------------------------- // Returns the NSView* associated with this vtkRenderWindow. -void *vtkCocoaRenderWindow::GetDisplayId() +void *vtkCocoaRenderWindow::GetWindowId() { NSMutableDictionary* manager = reinterpret_cast(this->GetCocoaManager()); - return reinterpret_cast([manager objectForKey:@"DisplayId"]); + return reinterpret_cast([manager objectForKey:@"WindowId"]); } //---------------------------------------------------------------------------- // Sets the NSView* associated with this vtkRenderWindow. -void vtkCocoaRenderWindow::SetDisplayId(void *arg) +void vtkCocoaRenderWindow::SetWindowId(void *arg) { if (arg != NULL) { NSMutableDictionary* manager = reinterpret_cast(this->GetCocoaManager()); [manager setObject:reinterpret_cast(arg) - forKey:@"DisplayId"]; + forKey:@"WindowId"]; } else { NSMutableDictionary* manager = reinterpret_cast(this->GetCocoaManager()); - [manager removeObjectForKey:@"DisplayId"]; + [manager removeObjectForKey:@"WindowId"]; } } @@ -1034,7 +1034,7 @@ (void)sscanf(info, "%tu", &tmp); } - this->SetDisplayId (reinterpret_cast(tmp)); + this->SetWindowId (reinterpret_cast(tmp)); } //---------------------------------------------------------------------------- @@ -1080,7 +1080,7 @@ NSPoint newViewPoint = NSMakePoint (x, y); // Convert to screen coordinates. - NSView* view = (NSView*)this->GetDisplayId(); + NSView* view = (NSView*)this->GetWindowId(); if (view) { NSPoint screenPoint = [view convertPoint:newViewPoint toView:nil]; Index: Rendering/vtkCocoaRenderWindowInteractor.mm =================================================================== RCS file: /cvsroot/VTK/VTK/Rendering/vtkCocoaRenderWindowInteractor.mm,v retrieving revision 1.26 diff -u -r1.26 vtkCocoaRenderWindowInteractor.mm --- Rendering/vtkCocoaRenderWindowInteractor.mm 22 Jan 2009 16:58:21 -0000 1.26 +++ Rendering/vtkCocoaRenderWindowInteractor.mm 10 Feb 2009 16:13:42 -0000 @@ -207,26 +207,26 @@ NSWindow *win = nil; if (renWin != NULL) { - win = reinterpret_cast(renWin->GetWindowId()); + win = reinterpret_cast(renWin->GetRootWindow()); - // We don't want to be informed of every window closing, so check for nil. + // We don't want to be informed of every window closing, so check for nil. if (win != nil) - { + { // Register for the windowWillClose notification in order to stop // the run loop if the window closes. NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(windowWillClose:) name:@"NSWindowWillCloseNotification" object:win]; - } + } } // Now that we are about to begin the standard Cocoa event loop, we can get // rid of the 'pool of last resort' because [NSApp run] will create a new // pool for every event #ifndef __OBJC_GC__ - delete gEarlyCocoaSetup; - gEarlyCocoaSetup = 0; +// delete gEarlyCocoaSetup; +// gEarlyCocoaSetup = 0; #endif // Start the NSApplication's run loop @@ -240,7 +240,7 @@ NSWindow *win = nil; if (renWin != NULL) { - win = reinterpret_cast(renWin->GetWindowId()); + win = reinterpret_cast(renWin->GetRootWindow()); } // Close the window, removing it from the screen and releasing it @@ -277,7 +277,7 @@ [NSApp postEvent:event atStart:YES]; // The NSWindow is closing, so prevent anyone from accidently using it - renWin->SetWindowId(NULL); + renWin->SetRootWindow(NULL); } } }