Drag'n'drop : moved "setAcceptDragOperation" functions at window level
authorDamien Plisson <damien.plisson@yahoo.fr>
Thu, 19 Nov 2009 08:56:26 +0000 (08:56 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Thu, 19 Nov 2009 08:56:26 +0000 (08:56 +0000)
GHOST/Cocoa : changed strings encoding to isoLatin1 (was UTF-8)

intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/GHOST_IWindow.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_System.h
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_Window.cpp
intern/ghost/intern/GHOST_Window.h
intern/ghost/intern/GHOST_WindowCocoa.mm

index 5e434c0eaa09a49da1e4b71ce679ea35ca3894db..d4788ae9e86eef27d64d2342db9f347cb5f9a14a 100644 (file)
@@ -414,7 +414,7 @@ extern GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
 /**
  * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
  */
-extern void GHOST_setAcceptDragOperation(GHOST_SystemHandle systemhandle, GHOST_TInt8 canAccept);
+extern void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 canAccept);
        
        
 /**
index e56a0dae879df1f2282a15fdbbccbb5067d5fbf8..305caa70ae4a5991814a6145e5af5c3b3b5407b9 100644 (file)
@@ -369,21 +369,6 @@ public:
        virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
 
        
-       /***************************************************************************************
-        ** Drag'n'drop operations
-        ***************************************************************************************/
-       
-       /**
-        * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
-        */
-       virtual void setAcceptDragOperation(bool canAccept) = 0;
-       
-       /**
-        * Returns acceptance of the dropped object
-        * Usually called by the "object dropped" event handling function
-        */
-       virtual bool canAcceptDragOperation() const = 0;
-       
 protected:
        /**
         * Initialize the system.
index 512fad877cb1d2cc6a3842537cddcf70236d9f95..5d1e0a67e7ee5002ec4d222bfd6588b44c450314 100644 (file)
@@ -148,6 +148,17 @@ public:
         */
        virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const = 0;
 
+       /**
+        * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
+        */
+       virtual void setAcceptDragOperation(bool canAccept) = 0;
+       
+       /**
+        * Returns acceptance of the dropped object
+        * Usually called by the "object dropped" event handling function
+        */
+       virtual bool canAcceptDragOperation() const = 0;
+       
        /**
         * Returns the state of the window (normal, minimized, maximized).
         * @return The state of the window.
index 76b3d7caf7e5bff01589a35e51c5ca82a0a306ee..556176809f459ebc03daa9f4a139b50ae1026541 100644 (file)
@@ -404,11 +404,11 @@ GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
 }
 
 
-void GHOST_setAcceptDragOperation(GHOST_SystemHandle systemhandle, GHOST_TInt8 canAccept)
+void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 canAccept)
 {
-       GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
+       GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
 
-       system->setAcceptDragOperation(canAccept);
+       window->setAcceptDragOperation(canAccept);
 }
 
 
index cccee12d6964d69fd3436e6007f2275703e2827b..79d8389ffc6d6f24fc337f8fccce042e4133d6de 100644 (file)
@@ -54,7 +54,6 @@
 GHOST_System::GHOST_System()
 : m_displayManager(0), m_timerManager(0), m_windowManager(0), m_eventManager(0), m_ndofManager(0)
 {
-       m_canAcceptDragOperation = false;
 }
 
 
@@ -276,16 +275,6 @@ GHOST_TSuccess GHOST_System::getButtonState(GHOST_TButtonMask mask, bool& isDown
        return success;
 }
 
-void GHOST_System::setAcceptDragOperation(bool canAccept)
-{
-       m_canAcceptDragOperation = canAccept;
-}
-
-bool GHOST_System::canAcceptDragOperation() const
-{
-       return m_canAcceptDragOperation;
-}
-
 GHOST_TSuccess GHOST_System::init()
 {
        m_timerManager = new GHOST_TimerManager ();
index 542553e830e7811680979a267b2080917a6f7085..e381b673957ae47a0ca3ac8c67ba2369bff2d4b8 100644 (file)
@@ -232,21 +232,6 @@ public:
         */
        virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& isDown) const;
        
-       /***************************************************************************************
-        ** Drag'n'drop operations
-        ***************************************************************************************/
-       
-       /**
-        * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
-        */
-       virtual void setAcceptDragOperation(bool canAccept);
-       
-       /**
-        * Returns acceptance of the dropped object
-        * Usually called by the "object dropped" event handling function
-        */
-       virtual bool canAcceptDragOperation() const;
-
        /***************************************************************************************
         ** Other (internal) functionality.
         ***************************************************************************************/
@@ -348,9 +333,6 @@ protected:
     /** The N-degree of freedom device manager */
     GHOST_NDOFManager* m_ndofManager;
        
-       /** The acceptance of the "drop candidate" of the current drag'n'drop operation */
-       bool m_canAcceptDragOperation;
-
        /** Prints all the events. */
 #ifdef GHOST_DEBUG
        GHOST_EventPrinter* m_eventPrinter;
index b31db472ef16d90addfaa2ee8a382bc04b401db2..86203a49da79760a9c3bb7086d3704d1aee603d8 100644 (file)
@@ -892,7 +892,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
        switch(eventType) 
        {
                case GHOST_kEventDraggingEntered:
-                       setAcceptDragOperation(FALSE); //Drag operation needs to be accepted explicitely by the event manager
                case GHOST_kEventDraggingUpdated:
                case GHOST_kEventDraggingExited:
                        pushEvent(new GHOST_EventDragnDrop(getMilliSeconds(),eventType,draggedObjectType,window,mouseX,mouseY,NULL));
@@ -931,7 +930,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
                                        {
                                                droppedStr = [droppedArray objectAtIndex:i];
                                                
-                                               pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+                                               pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding];
                                                temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
                                        
                                                if (!temp_buff) {
@@ -939,7 +938,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
                                                        break;
                                                }
                                        
-                                               strncpy((char*)temp_buff, [droppedStr UTF8String], pastedTextSize);
+                                               strncpy((char*)temp_buff, [droppedStr cStringUsingEncoding:NSISOLatin1StringEncoding], pastedTextSize);
                                                temp_buff[pastedTextSize] = '\0';
                                                
                                                strArray->strings[i] = temp_buff;
@@ -950,7 +949,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
                                        
                                case GHOST_kDragnDropTypeString:
                                        droppedStr = (NSString*)data;
-                                       pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+                                       pastedTextSize = [droppedStr lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding];
                                        
                                        temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
                                        
@@ -958,7 +957,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType
                                                return GHOST_kFailure;
                                        }
                                        
-                                       strncpy((char*)temp_buff, [droppedStr UTF8String], pastedTextSize);
+                                       strncpy((char*)temp_buff, [droppedStr cStringUsingEncoding:NSISOLatin1StringEncoding], pastedTextSize);
                                        
                                        temp_buff[pastedTextSize] = '\0';
                                        
@@ -1321,7 +1320,7 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
        }
        
        NSArray *supportedTypes =
-               [NSArray arrayWithObjects: @"public.utf8-plain-text", nil];
+               [NSArray arrayWithObjects: NSStringPboardType, nil];
        
        NSString *bestType = [[NSPasteboard generalPasteboard]
                                                  availableTypeFromArray:supportedTypes];
@@ -1331,14 +1330,14 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
                return NULL;
        }
        
-       NSString * textPasted = [pasteBoard stringForType:@"public.utf8-plain-text"];
+       NSString * textPasted = [pasteBoard stringForType:NSStringPboardType];
 
        if (textPasted == nil) {
                [pool drain];
                return NULL;
        }
        
-       pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+       pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSISOLatin1StringEncoding];
        
        temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1); 
 
@@ -1347,7 +1346,7 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
                return NULL;
        }
        
-       strncpy((char*)temp_buff, [textPasted UTF8String], pastedTextSize);
+       strncpy((char*)temp_buff, [textPasted cStringUsingEncoding:NSISOLatin1StringEncoding], pastedTextSize);
        
        temp_buff[pastedTextSize] = '\0';
        
@@ -1375,13 +1374,13 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
                return;
        }
        
-       NSArray *supportedTypes = [NSArray arrayWithObject:@"public.utf8-plain-text"];
+       NSArray *supportedTypes = [NSArray arrayWithObject:NSStringPboardType];
        
        [pasteBoard declareTypes:supportedTypes owner:nil];
        
-       textToCopy = [NSString stringWithUTF8String:buffer];
+       textToCopy = [NSString stringWithCString:buffer encoding:NSISOLatin1StringEncoding];
        
-       [pasteBoard setString:textToCopy forType:@"public.utf8-plain-text"];
+       [pasteBoard setString:textToCopy forType:NSStringPboardType];
        
        [pool drain];
 }
index 33484284d7c64d1314fa2b62074b2b90566ba3c9..e89e0274276ca65549703565e9559d0ff1ed0cda 100644 (file)
@@ -53,6 +53,7 @@ GHOST_Window::GHOST_Window(
        m_stereoVisual(stereoVisual)
 {
        m_isUnsavedChanges = false;
+       m_canAcceptDragOperation = false;
        
     m_cursorGrabAccumPos[0] = 0;
     m_cursorGrabAccumPos[1] = 0;
@@ -154,6 +155,15 @@ GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUn
        }
 }
 
+void GHOST_Window::setAcceptDragOperation(bool canAccept)
+{
+       m_canAcceptDragOperation = canAccept;
+}
+
+bool GHOST_Window::canAcceptDragOperation() const
+{
+       return m_canAcceptDragOperation;
+}
 
 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
 {
index 86447a8623c533fe50c04f0e7022f56c7d00206f..1b5681dc41cafa71fbf08c97ca7c79b1d2e85a02 100644 (file)
@@ -183,6 +183,17 @@ public:
         */
        virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect& bounds);
 
+       /**
+        * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
+        */
+       virtual void setAcceptDragOperation(bool canAccept);
+       
+       /**
+        * Returns acceptance of the dropped object
+        * Usually called by the "object dropped" event handling function
+        */
+       virtual bool canAcceptDragOperation() const;
+       
        /**
         * Sets the window "modified" status, indicating unsaved changes
         * @param isUnsavedChanges Unsaved changes or not
@@ -294,6 +305,9 @@ protected:
        /** The current shape of the cursor */
        GHOST_TStandardCursor m_cursorShape;
     
+       /** The acceptance of the "drop candidate" of the current drag'n'drop operation */
+       bool m_canAcceptDragOperation;
+       
        /** Modified state : are there unsaved changes */
        bool m_isUnsavedChanges;
        
index 54a62636895065d46f31b6e02a52ef52243b1668..24abc9c45fc28276b405851c39dd9ff1976603f7 100644 (file)
@@ -153,6 +153,7 @@ extern "C" {
        else if ([[draggingPBoard types] containsObject:NSStringPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeString;
        else return NSDragOperationNone;
        
+       associatedWindow->setAcceptDragOperation(FALSE); //Drag operation needs to be accepted explicitly by the event manager
        systemCocoa->handleDraggingEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
        return NSDragOperationCopy;
 }
@@ -178,7 +179,7 @@ extern "C" {
 
 - (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
 {
-       if (systemCocoa->canAcceptDragOperation())
+       if (associatedWindow->canAcceptDragOperation())
                return YES;
        else
                return NO;
@@ -198,7 +199,7 @@ extern "C" {
                        data = [draggingPBoard propertyListForType:NSFilenamesPboardType];
                        break;
                case GHOST_kDragnDropTypeString:
-                       data = [draggingPBoard stringForType:@"public.utf8-plain-text"];
+                       data = [draggingPBoard stringForType:NSStringPboardType];
                        break;
                default:
                        return NO;