Revision: 24448
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24448
Author:   damien78
Date:     2009-11-10 13:56:46 +0100 (Tue, 10 Nov 2009)

Log Message:
-----------
Drag & drop implementation at GHOST level (only OSX for now)

The dragging sequence is performed in four phases:
 
- Start sequence (GHOST_kEventDraggingEntered) that tells a drag'n'drop 
operation has started. Already gives the object data type, and the entering 
mouse location

- Update mouse position (GHOST_kEventDraggingUpdated) sent upon each mouse move 
until the drag'n'drop operation stops, to give the updated mouse position.
Useful to highlight a potential destination, and update the status (through 
GHOST_setAcceptDragOperation) telling if the object can be dropped at the 
current cursor position.

- Abort drag'n'drop sequence (GHOST_kEventDraggingExited) sent when the user 
moved the mouse outside the window.

- Send the dropped data (GHOST_kEventDraggingDropDone)

- Outside of the normal sequence, dropped data can be sent 
(GHOST_kEventDraggingDropOnIcon). This can happen when the user drops an object 
on the application icon. (Also used in OSX to pass the filename of the document 
the user doubled-clicked in the finder)

Note that the event handler is responsible for freeing the received data.
And the mouse position is sent directly in blender client coordinates (y=0 at 
bottom)

The GHOST_setAcceptDragOperation(TRUE) call must be placed before the user 
drops the object for it to be accepted.

Current handled data types :
- Text string
- Array of filenames (full paths)
- Bitmap image (not implemented yet)

Modified Paths:
--------------
    trunk/blender/intern/ghost/GHOST_C-api.h
    trunk/blender/intern/ghost/GHOST_ISystem.h
    trunk/blender/intern/ghost/GHOST_Types.h
    trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
    trunk/blender/intern/ghost/intern/GHOST_System.cpp
    trunk/blender/intern/ghost/intern/GHOST_System.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm

Added Paths:
-----------
    trunk/blender/intern/ghost/intern/GHOST_EventDragnDrop.h

Modified: trunk/blender/intern/ghost/GHOST_C-api.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_C-api.h    2009-11-10 12:08:02 UTC (rev 
24447)
+++ trunk/blender/intern/ghost/GHOST_C-api.h    2009-11-10 12:56:46 UTC (rev 
24448)
@@ -406,7 +406,18 @@
                                                                                
   GHOST_TButtonMask mask,
                                                                                
   int* isDown);
 
+
+/***************************************************************************************
+ ** Drag'n'drop operations
+ 
***************************************************************************************/
+
 /**
+ * Tells if the ongoing drag'n'drop object can be accepted upon mouse drop
+ */
+extern void GHOST_setAcceptDragOperation(GHOST_SystemHandle systemhandle, 
GHOST_TInt8 canAccept);
+       
+       
+/**
  * Returns the event type.
  * @param eventhandle The handle to the event
  * @return The event type.

Modified: trunk/blender/intern/ghost/GHOST_ISystem.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_ISystem.h  2009-11-10 12:08:02 UTC (rev 
24447)
+++ trunk/blender/intern/ghost/GHOST_ISystem.h  2009-11-10 12:56:46 UTC (rev 
24448)
@@ -351,6 +351,11 @@
         */
        virtual GHOST_TSuccess getButtonState(GHOST_TButtonMask mask, bool& 
isDown) const = 0;
 
+       
+       
/***************************************************************************************
+        ** Access to clipboard.
+        
***************************************************************************************/
+       
        /**
         * Returns the selection buffer
         * @return Returns "unsinged char" from X11 XA_CUT_BUFFER0 buffer
@@ -363,6 +368,22 @@
         */
        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.

Modified: trunk/blender/intern/ghost/GHOST_Types.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_Types.h    2009-11-10 12:08:02 UTC (rev 
24447)
+++ trunk/blender/intern/ghost/GHOST_Types.h    2009-11-10 12:56:46 UTC (rev 
24448)
@@ -167,6 +167,12 @@
        GHOST_kEventWindowUpdate,
        GHOST_kEventWindowSize,
        GHOST_kEventWindowMove,
+       
+       GHOST_kEventDraggingEntered,
+       GHOST_kEventDraggingUpdated,
+       GHOST_kEventDraggingExited,
+       GHOST_kEventDraggingDropDone,
+       GHOST_kEventDraggingDropOnIcon,
 
        GHOST_kEventTimer,
 
@@ -368,6 +374,30 @@
 } GHOST_TEventWheelData;
 
 
+typedef enum {
+       GHOST_kDragnDropTypeUnknown =0,
+       GHOST_kDragnDropTypeFilenames, /*Array of strings representing file 
names (full path) */
+       GHOST_kDragnDropTypeString, /* Unformatted text UTF-8 string */
+       GHOST_kDragnDropTypeBitmap /*Bitmap image data */
+} GHOST_TDragnDropTypes;
+
+typedef struct {
+       /** The x-coordinate of the cursor position. */
+       GHOST_TInt32 x;
+       /** The y-coordinate of the cursor position. */
+       GHOST_TInt32 y;
+       /** The dropped item type */
+       GHOST_TDragnDropTypes dataType;
+       /** The "dropped content" */
+       GHOST_TEventDataPtr data;
+} GHOST_TEventDragnDropData;
+
+typedef struct {
+       int count;
+       GHOST_TUns8 **strings;
+} GHOST_TStringArray;
+
+
 /* original patch used floats, but the driver return ints and uns. We will 
calibrate in view, no sense on doing conversions twice */
 /* as all USB device controls are likely to use ints, this is also more future 
proof */
 //typedef struct {

Modified: trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_C-api.cpp   2009-11-10 12:08:02 UTC 
(rev 24447)
+++ trunk/blender/intern/ghost/intern/GHOST_C-api.cpp   2009-11-10 12:56:46 UTC 
(rev 24448)
@@ -404,7 +404,14 @@
 }
 
 
+void GHOST_setAcceptDragOperation(GHOST_SystemHandle systemhandle, GHOST_TInt8 
canAccept)
+{
+       GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
 
+       system->setAcceptDragOperation(canAccept);
+}
+
+
 GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
 {
        GHOST_IEvent* event = (GHOST_IEvent*) eventhandle;

Added: trunk/blender/intern/ghost/intern/GHOST_EventDragnDrop.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_EventDragnDrop.h                    
        (rev 0)
+++ trunk/blender/intern/ghost/intern/GHOST_EventDragnDrop.h    2009-11-10 
12:56:46 UTC (rev 24448)
@@ -0,0 +1,91 @@
+/**
+ * $Id: GHOST_EventDragnDrop.h 13161 2008-01-07 19:13:47Z hos $
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Damien Plisson 11/2009
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef _GHOST_EVENT_DRAGNDROP_H_
+#define _GHOST_EVENT_DRAGNDROP_H_
+
+#include "GHOST_Event.h"
+
+/**
+ * Drag & drop event
+ * 
+ * The dragging sequence is performed in four phases:
+ * 
+ * <li> Start sequence (GHOST_kEventDraggingEntered) that tells a drag'n'drop 
operation has started. Already gives the object data type,
+ * and the entering mouse location
+ *
+ * <li> Update mouse position (GHOST_kEventDraggingUpdated) sent upon each 
mouse move until the drag'n'drop operation stops, to give the updated mouse 
position.
+ * Useful to highlight a potential destination, and update the status (through 
GHOST_setAcceptDragOperation) telling if the object can be dropped at
+ * the current cursor position.
+ *
+ * <li> Abort drag'n'drop sequence (GHOST_kEventDraggingExited) sent when the 
user moved the mouse outside the window.
+ *
+ * <li> Send the dropped data (GHOST_kEventDraggingDropDone)
+ *
+ * <li> Outside of the normal sequence, dropped data can be sent 
(GHOST_kEventDraggingDropOnIcon). This can happen when the user drops an object
+ * on the application icon. (Also used in OSX to pass the filename of the 
document the user doubled-clicked in the finder)
+ *
+ * <br><br>Note that the event handler is responsible for freeing the received 
data.
+ * <br>And the mouse positions are given in Blender coordinates (y=0 at bottom)
+ *
+ * <br>Currently supported object types :
+ * <li>UTF-8 string
+ * <li>array of strings representing filenames (GHOST_TStringArray)
+ * <li>bitmap image
+ */
+class GHOST_EventDragnDrop : public GHOST_Event
+{
+public:
+       /**
+        * Constructor.
+        * @param time          The time this event was generated.
+        * @param type          The type of this event.
+        * @param dataType      The type of the drop candidate object
+        * @param window        The window where the event occured
+        * @param x                     The x-coordinate of the location the 
cursor was at at the time of the event.
+        * @param y                     The y-coordinate of the location the 
cursor was at at the time of the event.
+        * @param data          The "content" dropped in the window
+        */
+       GHOST_EventDragnDrop(GHOST_TUns64 time, GHOST_TEventType type, 
GHOST_TDragnDropTypes dataType, GHOST_IWindow* window,
+                                                int x, int y, 
GHOST_TEventDataPtr data)
+               : GHOST_Event(time, type, window)
+       {
+               m_dragnDropEventData.x = x;
+               m_dragnDropEventData.y = y;
+               m_dragnDropEventData.dataType = dataType;
+               m_dragnDropEventData.data = data;
+               m_data = &m_dragnDropEventData;
+       }
+
+protected:
+       /** The x,y-coordinates of the cursor position. */
+       GHOST_TEventDragnDropData m_dragnDropEventData;
+};
+
+#endif // _GHOST_EVENT_DRAGNDROP_H_
+

Modified: trunk/blender/intern/ghost/intern/GHOST_System.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.cpp  2009-11-10 12:08:02 UTC 
(rev 24447)
+++ trunk/blender/intern/ghost/intern/GHOST_System.cpp  2009-11-10 12:56:46 UTC 
(rev 24448)
@@ -54,6 +54,7 @@
 GHOST_System::GHOST_System()
 : m_displayManager(0), m_timerManager(0), m_windowManager(0), 
m_eventManager(0), m_ndofManager(0)
 {
+       m_canAcceptDragOperation = false;
 }
 
 
@@ -275,7 +276,16 @@
        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 ();

Modified: trunk/blender/intern/ghost/intern/GHOST_System.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.h    2009-11-10 12:08:02 UTC 
(rev 24447)
+++ trunk/blender/intern/ghost/intern/GHOST_System.h    2009-11-10 12:56:46 UTC 
(rev 24448)
@@ -231,6 +231,21 @@
         * @return                      Indication of success.
         */
        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.

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to