Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_WindowCocoa.mm
| Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| - (GHOST_SystemCocoa *)systemCocoa | - (GHOST_SystemCocoa *)systemCocoa | ||||
| { | { | ||||
| return systemCocoa; | return systemCocoa; | ||||
| } | } | ||||
| - (BOOL)canBecomeKeyWindow | - (BOOL)canBecomeKeyWindow | ||||
| { | { | ||||
| /* Don't make other windows active when mouse events are captured. */ | |||||
| if (systemCocoa->m_windowMouseCaptured && systemCocoa->m_windowMouseCaptured != associatedWindow) { | |||||
| return NO; | |||||
| } | |||||
| /* Don't make other windows active when a dialog window is open. */ | /* Don't make other windows active when a dialog window is open. */ | ||||
| return (associatedWindow->isDialog() || !systemCocoa->hasDialogWindow()); | return (associatedWindow->isDialog() || !systemCocoa->hasDialogWindow()); | ||||
| } | } | ||||
| // The drag'n'drop dragging destination methods | // The drag'n'drop dragging destination methods | ||||
| - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender | - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender | ||||
| { | { | ||||
| NSPoint mouseLocation = [sender draggingLocation]; | NSPoint mouseLocation = [sender draggingLocation]; | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa, | ||||
| bool is_debug, | bool is_debug, | ||||
| bool is_dialog, | bool is_dialog, | ||||
| GHOST_WindowCocoa *parentWindow) | GHOST_WindowCocoa *parentWindow) | ||||
| : GHOST_Window(width, height, state, stereoVisual, false), | : GHOST_Window(width, height, state, stereoVisual, false), | ||||
| m_openGLView(nil), | m_openGLView(nil), | ||||
| m_metalView(nil), | m_metalView(nil), | ||||
| m_metalLayer(nil), | m_metalLayer(nil), | ||||
| m_systemCocoa(systemCocoa), | m_systemCocoa(systemCocoa), | ||||
| m_hasGrabMouse(false), | |||||
| m_nPressedButtons(0), | |||||
| m_customCursor(0), | m_customCursor(0), | ||||
| m_immediateDraw(false), | m_immediateDraw(false), | ||||
| m_debug_context(is_debug), | m_debug_context(is_debug), | ||||
| m_is_dialog(is_dialog) | m_is_dialog(is_dialog) | ||||
| { | { | ||||
| m_fullScreen = false; | m_fullScreen = false; | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| ▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa, | ||||
| [pool drain]; | [pool drain]; | ||||
| } | } | ||||
| GHOST_WindowCocoa::~GHOST_WindowCocoa() | GHOST_WindowCocoa::~GHOST_WindowCocoa() | ||||
| { | { | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| if (m_systemCocoa->m_windowMouseCaptured == this) { | |||||
| m_systemCocoa->m_windowMouseCaptured = nil; | |||||
| } | |||||
| if (m_customCursor) { | if (m_customCursor) { | ||||
| [m_customCursor release]; | [m_customCursor release]; | ||||
| m_customCursor = nil; | m_customCursor = nil; | ||||
| } | } | ||||
| releaseNativeHandles(); | releaseNativeHandles(); | ||||
| if (m_openGLView) { | if (m_openGLView) { | ||||
| ▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | if (context->initializeDrawingContext()) | ||||
| return context; | return context; | ||||
| else | else | ||||
| delete context; | delete context; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| #pragma mark Mouse Capture | |||||
| void GHOST_WindowCocoa::lostMouseCapture() | |||||
| { | |||||
| if (m_systemCocoa->m_windowMouseCaptured == this) { | |||||
| m_systemCocoa->m_windowMouseCaptured = nil; | |||||
| m_hasGrabMouse = false; | |||||
| m_nPressedButtons = 0; | |||||
| } | |||||
| } | |||||
| void GHOST_WindowCocoa::updateMouseCapture(GHOST_MouseCaptureEventCocoa event) | |||||
| { | |||||
| switch (event) { | |||||
| case MousePressed: | |||||
| m_nPressedButtons++; | |||||
| break; | |||||
| case MouseReleased: | |||||
| if (m_nPressedButtons) | |||||
| m_nPressedButtons--; | |||||
| break; | |||||
| case OperatorGrab: | |||||
| m_hasGrabMouse = true; | |||||
| break; | |||||
| case OperatorUngrab: | |||||
| m_hasGrabMouse = false; | |||||
| break; | |||||
| } | |||||
| const bool hasMouseCaptured = m_systemCocoa->m_windowMouseCaptured == this; | |||||
| if (!m_nPressedButtons && !m_hasGrabMouse && hasMouseCaptured) { | |||||
| m_systemCocoa->m_windowMouseCaptured = nil; | |||||
| } | |||||
| else if ((m_nPressedButtons || m_hasGrabMouse) && !hasMouseCaptured) { | |||||
| m_systemCocoa->m_windowMouseCaptured = this; | |||||
| } | |||||
| } | |||||
| #pragma mark invalidate | #pragma mark invalidate | ||||
| GHOST_TSuccess GHOST_WindowCocoa::invalidate() | GHOST_TSuccess GHOST_WindowCocoa::invalidate() | ||||
| { | { | ||||
| GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid"); | GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid"); | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| NSView *view = (m_openGLView) ? m_openGLView : m_metalView; | NSView *view = (m_openGLView) ? m_openGLView : m_metalView; | ||||
| [view setNeedsDisplay:YES]; | [view setNeedsDisplay:YES]; | ||||
| ▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | if (mode != GHOST_kGrabNormal) { | ||||
| setWindowCursorVisibility(false); | setWindowCursorVisibility(false); | ||||
| } | } | ||||
| // Make window key if it wasn't to get the mouse move events | // Make window key if it wasn't to get the mouse move events | ||||
| [m_window makeKeyWindow]; | [m_window makeKeyWindow]; | ||||
| [pool drain]; | [pool drain]; | ||||
| } | } | ||||
| updateMouseCapture(OperatorGrab); | |||||
| } | } | ||||
| else { | else { | ||||
| if (m_cursorGrab == GHOST_kGrabHide) { | if (m_cursorGrab == GHOST_kGrabHide) { | ||||
| m_systemCocoa->setCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]); | m_systemCocoa->setCursorPosition(m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]); | ||||
| setWindowCursorVisibility(true); | setWindowCursorVisibility(true); | ||||
| } | } | ||||
| /* Almost works without but important otherwise the mouse GHOST location | /* Almost works without but important otherwise the mouse GHOST location | ||||
| * can be incorrect on exit. */ | * can be incorrect on exit. */ | ||||
| setCursorGrabAccum(0, 0); | setCursorGrabAccum(0, 0); | ||||
| m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1; /* disable */ | m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1; /* disable */ | ||||
| updateMouseCapture(OperatorUngrab); | |||||
| } | } | ||||
| return err; | return err; | ||||
| } | } | ||||
| GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor shape) | GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor shape) | ||||
| { | { | ||||
| NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | ||||
| ▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines | |||||