merge with trunk at r27259 and commit of a patch by anthony jones to fix msvc (though...
[blender-staging.git] / intern / ghost / intern / GHOST_WindowCocoa.mm
index 873a59251026b6f853c24bcbf6cce2274bf4c8a9..6206388fdaab1496fa865648668d8bb7cc5d047a 100644 (file)
@@ -14,7 +14,7 @@
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software Foundation,\r
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *\r
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.\r
  * All rights reserved.\r
@@ -72,6 +72,8 @@ extern "C" {
 - (void)windowDidResignKey:(NSNotification *)notification;\r
 - (void)windowDidExpose:(NSNotification *)notification;
 - (void)windowDidResize:(NSNotification *)notification;\r
+- (void)windowDidMove:(NSNotification *)notification;
+- (void)windowWillMove:(NSNotification *)notification;
 @end\r
 \r
 @implementation CocoaWindowDelegate : NSObject\r
@@ -101,6 +103,16 @@ extern "C" {
        systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);\r
 }\r
 \r
+- (void)windowDidMove:(NSNotification *)notification
+{
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
+}
+
+- (void)windowWillMove:(NSNotification *)notification
+{
+       systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
+}
+
 - (void)windowDidResize:(NSNotification *)notification\r
 {\r
 #ifdef MAC_OS_X_VERSION_10_6
@@ -170,7 +182,7 @@ extern "C" {
        NSPoint mouseLocation = [sender draggingLocation];
        
        systemCocoa->handleDraggingEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
-       return NSDragOperationCopy;
+       return associatedWindow->canAcceptDragOperation()?NSDragOperationCopy:NSDragOperationNone;
 }
 
 - (void)draggingExited:(id < NSDraggingInfo >)sender
@@ -191,11 +203,16 @@ extern "C" {
 {
        NSPoint mouseLocation = [sender draggingLocation];
        NSPasteboard *draggingPBoard = [sender draggingPasteboard];
+       NSImage *droppedImg;
        id data;
        
        switch (m_draggedObjectType) {
                case GHOST_kDragnDropTypeBitmap:
-                       data = [draggingPBoard dataForType:NSTIFFPboardType];
+                       if([NSImage canInitWithPasteboard:draggingPBoard]) {
+                               droppedImg = [[NSImage alloc]initWithPasteboard:draggingPBoard];
+                               data = droppedImg; //[draggingPBoard dataForType:NSTIFFPboardType];
+                       }
+                       else return NO;
                        break;
                case GHOST_kDragnDropTypeFilenames:
                        data = [draggingPBoard propertyListForType:NSFilenamesPboardType];
@@ -324,6 +341,11 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
        // Pixel Format Attributes for the windowed NSOpenGLContext
        i=0;
        pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
+       
+       // Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object’s flushBuffer
+       // needed for 'Draw Overlap' drawing method
+       pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore; 
+       
        pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
        //pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,;   // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
        
@@ -354,6 +376,11 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
        if (pixelFormat == nil) {
                i=0;
                pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
+               
+               // Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object’s flushBuffer
+               // needed for 'Draw Overlap' drawing method
+               pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
+               
                pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
                //pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,;   // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
                
@@ -443,6 +470,10 @@ bool GHOST_WindowCocoa::getValid() const
        return (m_window != 0);
 }\r
 \r
+void* GHOST_WindowCocoa::getOSWindow() const
+{
+       return (void*)m_window;
+}
 \r
 void GHOST_WindowCocoa::setTitle(const STR_String& title)\r
 {\r
@@ -823,6 +854,8 @@ GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
 \r
 GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)\r
 {\r
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       
        GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")\r
     if (order == GHOST_kWindowOrderTop) {\r
                [m_window makeKeyAndOrderFront:nil];
@@ -838,6 +871,8 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
                        [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
                }
     }\r
+       
+       [pool drain];
     return GHOST_kSuccess;\r
 }\r
 \r
@@ -1042,6 +1077,7 @@ void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) c
                        case GHOST_kStandardCursorTopRightCorner:\r
                        case GHOST_kStandardCursorBottomRightCorner:\r
                        case GHOST_kStandardCursorBottomLeftCorner:\r
+                       case GHOST_kStandardCursorCopy:
                        case GHOST_kStandardCursorDefault:\r
                        default:\r
                                tmpCursor = [NSCursor arrowCursor];\r
@@ -1073,6 +1109,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
                //No need to perform grab without warp as it is always on in OS X\r
                if(mode != GHOST_kGrabNormal) {
                        GHOST_TInt32 x_old,y_old;\r
+                       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 \r
                        m_systemCocoa->getCursorPosition(x_old,y_old);\r
                        screenToClient(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
@@ -1083,8 +1120,13 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
                                setWindowCursorVisibility(false);
                        }
                        
+                       //Make window key if it wasn't to get the mouse move events
+                       [m_window makeKeyWindow];
+                       
                        //Dissociate cursor position even for warp mode, to allow mouse acceleration to work even when warping the cursor
                        err = CGAssociateMouseAndMouseCursorPosition(false) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
+                       
+                       [pool drain];
                }\r
        }\r
        else {\r