Skip to content

Commit

Permalink
Various Cocoa improvements and fixes
Browse files Browse the repository at this point in the history
Changed behaviour of vtkCocoaRenderWindowInteractor::TerminateApp().
It used to do one of two things: 1) terminate the application completely,
or 2) close the NSWindow and stop the event loop.  Now it never closes
the NSWindow, never terminates the application, and always stops the
event loop.  Start() and TerminateApp() are now pairs, which is how other
platforms already behave.  Also refactored NSApplication runloop
starting/stopping code into static functions that do only that.  Makes
more sense since there is only one event loop, there doesn't need to be
an association with any class or instance.  Thanks to Pat Marion for
reporting this problem and creating a patch.

Changed of behaviour observing for NSWindow closing.  First, moved the
private vtkCocoaServer class from vtkCocoaRenderWindowInteractor to
vtkCocoaRenderWindow.  Its job is to observe window closing.  Since
vtkCocoaRenderWindow creates the NSWindow, it make more sense there.
We were previously careful to only observe NSWindows created by VTK,
but are now also careful to *stop* observing only those same windows,
whereas previously there was an outside chance of stopping observation
of all window closes, which is something a library should not do
(who knows what else the application is doing).  Now when an observed
NSWindow closes, we no longer stop the event loop, but merely remove
our reference to it.

Changed vtkCocoaRenderWindow::SetWindowName() to interpret its char*
string parameter as UTF8 instead of ASCII.

Fixed possible memory leaks in ~vtkCocoaRenderWindow.

Replaced most invocations of 'autorelease' in favour of 'release'.
The motivation being that VTK, as a library, might sometimes be called
before an autorelease pool is even setup, so better to avoid autoreleased
objects as much as possible.

Fixed some whitespace and coding conventions
(asterisk positioning, constness, etc.)

Change-Id: I5a5d410012980ee9f6c637c340e98e3daa5aee74
  • Loading branch information
seanm committed Feb 14, 2014
1 parent 486a446 commit a3e9fc9
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 314 deletions.
8 changes: 4 additions & 4 deletions Rendering/OpenGL/vtkCocoaGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
class vtkCocoaRenderWindowInteractor;

// Type declarations
typedef vtkCocoaRenderWindow* vtkCocoaRenderWindowRef;
typedef vtkCocoaRenderWindowInteractor* vtkCocoaRenderWindowInteractorRef;
typedef vtkCocoaRenderWindow *vtkCocoaRenderWindowRef;
typedef vtkCocoaRenderWindowInteractor *vtkCocoaRenderWindowInteractorRef;
#else
// Type declarations
typedef void* vtkCocoaRenderWindowRef;
typedef void* vtkCocoaRenderWindowInteractorRef;
typedef void *vtkCocoaRenderWindowRef;
typedef void *vtkCocoaRenderWindowInteractorRef;
#endif

@interface vtkCocoaGLView : NSView
Expand Down
31 changes: 17 additions & 14 deletions Rendering/OpenGL/vtkCocoaGLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@implementation vtkCocoaGLView

//----------------------------------------------------------------------------
// Private
- (void)emptyMethod:(id)sender
{
(void)sender;
Expand Down Expand Up @@ -74,7 +75,7 @@ - (vtkCocoaRenderWindowInteractor *)getInteractor
{
if (_myVTKRenderWindow)
{
return (vtkCocoaRenderWindowInteractor*)_myVTKRenderWindow->GetInteractor();
return (vtkCocoaRenderWindowInteractor *)_myVTKRenderWindow->GetInteractor();
}
else
{
Expand All @@ -95,6 +96,7 @@ - (void)drawRect:(NSRect)theRect
}

//----------------------------------------------------------------------------
// Private
- (void)clearTrackingRect
{
// remove any tracking rect we have
Expand All @@ -106,6 +108,7 @@ - (void)clearTrackingRect
}

//----------------------------------------------------------------------------
// Private
- (void)resetTrackingRect
{
//clear out the old tracking rect
Expand Down Expand Up @@ -184,7 +187,7 @@ - (void)keyDown:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -256,7 +259,7 @@ - (void)keyUp:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -324,7 +327,7 @@ - (void)flagsChanged:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -407,7 +410,7 @@ - (void)mouseMoved:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -452,7 +455,7 @@ - (void)mouseEntered:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -487,7 +490,7 @@ - (void)mouseExited:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -522,7 +525,7 @@ - (void)scrollWheel:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -565,7 +568,7 @@ - (void)mouseDown:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -595,7 +598,7 @@ - (void)mouseDown:(NSEvent *)theEvent

interactor->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);

NSApplication* application = [NSApplication sharedApplication];
NSApplication *application = [NSApplication sharedApplication];
NSDate* infinity = [NSDate distantFuture];
do
{
Expand Down Expand Up @@ -643,7 +646,7 @@ - (void)rightMouseDown:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -673,7 +676,7 @@ - (void)rightMouseDown:(NSEvent *)theEvent

interactor->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);

NSApplication* application = [NSApplication sharedApplication];
NSApplication *application = [NSApplication sharedApplication];
NSDate* infinity = [NSDate distantFuture];
do
{
Expand Down Expand Up @@ -721,7 +724,7 @@ - (void)otherMouseDown:(NSEvent *)theEvent
return;
}

vtkCocoaRenderWindow* renWin =
vtkCocoaRenderWindow *renWin =
vtkCocoaRenderWindow::SafeDownCast([self getVTKRenderWindow]);

if (!renWin)
Expand Down Expand Up @@ -751,7 +754,7 @@ - (void)otherMouseDown:(NSEvent *)theEvent

interactor->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);

NSApplication* application = [NSApplication sharedApplication];
NSApplication *application = [NSApplication sharedApplication];
NSDate* infinity = [NSDate distantFuture];
do
{
Expand Down
3 changes: 3 additions & 0 deletions Rendering/OpenGL/vtkCocoaRenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ class VTKRENDERINGOPENGL_EXPORT vtkCocoaRenderWindow : public vtkOpenGLRenderWin
void SetCocoaManager(void *manager);
void *GetCocoaManager();

void SetCocoaServer(void *server); // Really a vtkCocoaServer*
void *GetCocoaServer();

private:
vtkCocoaRenderWindow(const vtkCocoaRenderWindow&); // Not implemented.
void operator=(const vtkCocoaRenderWindow&); // Not implemented.
Expand Down
Loading

0 comments on commit a3e9fc9

Please sign in to comment.