diff -r d8ad01792399 include/SDL_dnd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/SDL_dnd.h Thu Apr 16 18:18:15 2015 +0900 @@ -0,0 +1,141 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2014 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/** + * \file SDL_dnd.h + * + * Include file for SDL drag and drop handling + */ + +#ifndef _SDL_dnd_h +#define _SDL_dnd_h + +#include "SDL_stdinc.h" +#include "SDL_mimedata.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief Begin a drag and drop session. + * + * Can be called after receiving a valid drag begin event and before receiving + * a drag end event on the same dragID. Drag begin events can be obtained via + * hit testing the window with SDL_HITTEST_DRAGDATA. + * + * If an application accepts one of the mime types then an SDL_DRAGACCEPT event + * will be sent. + * If an application declines all of the mime types then an SDL_DRAGDECLINE + * event will be sent. + * Once the drag event is complete an SDL_DRAGEND event will be sent and the + * mime data object should be cleaned up. + * + * Mime data can be used to send any type of data including application specific + * data such as tabs or widgets. In this case set the surface to the tab + * contents and set the mime type to application/x-yourapplication-tab. + * + * If the system cannot support either full sized images/icons or the mime type + * SDL will try its best to emulate certain drag and drop features based on the + * mime type. + * + * \param dragID The dragID from the drag begin event. + * \param surface An image or icon for the drag session. + * \param data The mime data to send in the session. + * \param x The x co-ordinate of the surface relative to the drag begin. + * \param y The y co-ordinate of the surface relative to the drag begin. + * \sa SDL_StartDrag() + * \sa SDL_UpdateDrag() + */ +extern DECLSPEC int SDLCALL SDL_StartDrag(Uint32 dragID, SDL_MimeData *data, + SDL_Surface *surface, + Uint32 x, Uint32 y); + +/** + * \brief Update a drag and drop session. + * + * Can be called after starting a drag and drop session to update the image or + * icon. Data cannot be updated. + * + * \param dragID The dragID from the drag begin event. + * \param surface Thew new image or icon for the drag session. + * \param x The x co-ordinate of the surface relative to the start drag, + 0 for no change. + * \param y The y co-ordinate of the surface relative to the start drag, + 0 for no change. + * \sa SDL_StartDrag() + * \sa SDL_UpdateDrag() + */ +extern DECLSPEC int SDLCALL SDL_UpdateDrag(Uint32 dragID, SDL_Surface *surface, + Uint32 x, Uint32 y); + +/** + * \brief Callback used for accepting or declining a drag and drop events + * based on location. The mime_type data is allocated and deallocated by SDL. + * + * Traverse the mime_data list until you find the most acceptable mime_type + * for your application and then return the index. The mime data list will + * not contain any data at this point. + * + * If you wish to decline all mime types or the location is not acceptable for + * the drop return -1. + * + * \sa SDL_SetDropTestCallback + */ +typedef SInt32 (SDLCALL *SDL_DropTest)(SDL_Window *window, + const SDL_Point *area, + SDL_MimeData* mime_data, + void *callback_data); + +/** + * \brief Provide a callback that decides if a window region can accept drop + * data. + * + * This function lets the app provide a callback that allows areas of + * a given window to accept drop events. + * + * Specifying NULL for a callback disables drop-testing. drop-testing is + * disabled by default. + * + * Platforms that don't support this functionality will return -1 + * unconditionally, even if you're attempting to disable drop-testing. + * + * Since this can fire at any time, you should try to keep your callback + * efficient, devoid of allocations, etc. + * + * \param callback The callback to call when doing a drop-test. + * \param callback_data An app-defined void pointer passed to the callback. + * \return 0 on success, -1 on error (including unsupported). + */ +extern DECLSPEC int SDLCALL SDL_SetDropTestCallback(SDL_DropTest callback, + void *callback_data); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_dnd_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff -r d8ad01792399 include/SDL_events.h --- a/include/SDL_events.h Wed Apr 15 21:29:55 2015 +0200 +++ b/include/SDL_events.h Thu Apr 16 18:18:15 2015 +0900 @@ -133,7 +133,12 @@ /* Drag and drop events */ SDL_DROPFILE = 0x1000, /**< The system requests a file open */ - + SDL_DRAGDROP, /**< Generic data dropped into a window */ + SDL_DRAGBEGIN, /**< A hit test has passed and drag and drop can begin */ + SDL_DRAGACCEPTED, /**< The receiver accepts a mime type */ + SDL_DRAGDECLINED, /**< The receiver declined all data types */ + SDL_DRAGEND, /**< The drag and drop session ended */ + /* Audio hotplug events */ SDL_AUDIODEVICEADDED = 0x1100, /**< A new audio device is available */ SDL_AUDIODEVICEREMOVED, /**< An audio device has been removed. */ @@ -465,6 +470,26 @@ /** + * \brief An event used to send/receive generic drag and drop data. + * + * The application is responsible for freeing the SDL_MimeData object with + * SDL_DestroyMimeData() when itreceives either a SDL_DRAGDROP or SDL_DRAGEND. + * + */ +typedef struct SDL_DragDropEvent +{ + Uint32 type; /**< ::SDL_DRAGDROP through ::SDL_DRAGEND */ + Uint32 timestamp; + Uint32 windowID; /**< The window with drag focus, if any */ + Uint32 which; /**< The input instance id */ + Sint32 x; /**< X coordinate, relative to window */ + Sint32 y; /**< Y coordinate, relative to window */ + Uint32 dragID; /**< dragID */ + void *data1; /**< The SDL_MimeData */ +} SDL_DragDropEvent; + + +/** * \brief The "quit requested" event */ typedef struct SDL_QuitEvent @@ -542,6 +567,7 @@ SDL_MultiGestureEvent mgesture; /**< Gesture event data */ SDL_DollarGestureEvent dgesture; /**< Gesture event data */ SDL_DropEvent drop; /**< Drag and drop event data */ + SDL_DragDropEvent dragdrop; /**< Generic drag and drop event data */ /* This is necessary for ABI compatibility between Visual C++ and GCC Visual C++ will respect the push pack pragma and use 52 bytes for diff -r d8ad01792399 include/SDL_mimedata.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/SDL_mimedata.h Thu Apr 16 18:18:15 2015 +0900 @@ -0,0 +1,205 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2014 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/** + * \file SDL_mimedata.h + * + * Include file for SDL mime data handling + */ + +#ifndef _SDL_mimedata_h +#define _SDL_mimedata_h + +#include "SDL_stdinc.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief For each loop for traversing a mime data list + * + * TODO: Tidy/fix this macro + * + * Example use: + * + * SDL_MimeDataItem *item = NULL; + * const char *mime_type = NULL; + * Uint32 length = 0; + * const void *data = NULL; + * + * SDL_MimeDataForEach(mime_data, position, data, length, mime_type) { + * } + */ +#define SDL_MimeDataForEach(LIST, ITEM, DATA, LENGTH, TYPE) \ + for (ITEM = SDL_MimeDataNext(LIST, NULL); \ + ITEM != NULL; \ + ITEM = SDL_MimeDataNext(LIST, ITEM)) \ + if ((TYPE = SDL_MimeDataGetMime(LIST, ITEM)) && (1 || \ + (DATA = SDL_MimeDataGetData(LIST, ITEM, &LENGTH))) + +/** + * \brief A structure representing a mime data set + */ +struct SDL_MimeData; +typedef struct SDL_MimeData SDL_MimeData; + +/** + * \brief A structure representing an item in the mime data set + */ +struct SDL_MimeDataItem; +typedef struct SDL_MimeDataItem SDL_MimeDataItem; + +/* Function prototypes */ + +/** + * \brief Create a mime data set for drag and drop operations. + * + * All data in the object will become owned by SDL and will remain valid until + * the mime data object is destroyed with SDL_DestroyMimeData. + * + * This list may internally created using different methods and does not expose + * its members directly. + * + * \return A valid mime data object or NULL if there was an error. + * + * \sa SDL_CreateMimeData() + * \sa SDL_DestroyMimeData() + */ +extern DECLSPEC SDL_MimeData *SDLCALL SDL_CreateMimeData(); + +/** + * \brief Associate a buffer with a specific mime type. + * + * \param mime_data The mime data object to add to. + * \param mime_type The mime type of the data. + * \param data A pointer to the data. + * \param length The length of the data in bytes. + * + * \return 0 on success, or -1 on error + */ +extern DECLSPEC int SDLCALL SDL_MimeDataAdd(SDL_MimeData *mime_data, + const char *mime_type, void *data, + Uint32 length); + +/** + * \brief Remove any data with a specific mime type. + * + * \param mime_data The mime data object to add to. + * \param mime_type The mime type of the data to remove. + * + * \return 0 on success, or -1 on error + */ +extern DECLSPEC int SDLCALL SDL_MimeDataRemove(SDL_MimeData *mime_data, + const char *mime_type); + +/** + * \brief Check to see if a mime type has data associated. + * + * \param mime_data The mime data object to add to. + * \param mime_type The mime type of the data to remove. + * + * \return SDL_TRUE if the mime type has data or SDL_FALSE otherwise + */ +extern DECLSPEC SDL_bool SDLCALL SDL_MimeDataContains(SDL_MimeData *mime_data, + const char *mime_type); + +/** + * \brief Loop through the mime types in the list + * + * \param mime_data The mime data object to loop through. + * \param position Position in the list, NULL for the start. + * + * \return Pointer to the mime type or NULL if there was an error. + */ +extern DECLSPEC const SDL_MimeDataItem *SDLCALL SDL_MimeDataNext( + SDL_MimeData *mime_data, + SDL_MimeDataItem *position); + +/** + * \brief Return the mime type at the current position + * + * \param mime_data The mime data object to look in. + * \param item Item in the list. + * + * \return Pointer to the mime type. + */ +extern DECLSPEC const char *SDLCALL SDL_MimeDataGetMime(SDL_MimeData *mime_data, + SDL_MimeDataItem *item); + +/** + * \brief Return the data at the current position + * + * \param mime_data The mime data object to look in. + * \param item Item in the list. + * \param length The returned length of the data. + * + * \return Pointer to the data. + */ +extern DECLSPEC const void *SDLCALL SDL_MimeDataGetData(SDL_MimeData *mime_data, + SDL_MimeDataItem *item, + Uint32 *length); + +/** + * \brief Return the length of the mime data list + * + * \param mime_data The mime data object to look in. + * + * \return Length of the mime data list. + */ +extern DECLSPEC Uint32 SDLCALL SDL_MimeDataLength(SDL_MimeData *mime_data); + +/** + * \brief Find and return the data associated with a mime type + * + * \param mime_data The mime data object to look in. + * \param mime_type The mime type of the data to find. + * \param length The returned length of the data. + * + * \return Pointer to the data or NULL if there was an error. + */ +extern DECLSPEC const void *SDLCALL SDL_MimeDataFind(SDL_MimeData *mime_data, + const char *mime_type, + Uint32 *length); + +/** + * \brief Destroy and cleanup the mime data object + * + * \param mime_data The mime data object to cleanup. + * + * \return 0 on success, or -1 on error + * + * \sa SDL_CreateMimeData() + * \sa SDL_DestroyMimeData() + */ +extern DECLSPEC int SDLCALL SDL_DestroyMimeData(SDL_MimeData *mime_data); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +} +#endif +#include "close_code.h" + +#endif /* _SDL_mimedata_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff -r d8ad01792399 include/SDL_video.h --- a/include/SDL_video.h Wed Apr 15 21:29:55 2015 +0200 +++ b/include/SDL_video.h Thu Apr 16 18:18:15 2015 +0900 @@ -826,7 +826,8 @@ SDL_HITTEST_RESIZE_BOTTOMRIGHT, SDL_HITTEST_RESIZE_BOTTOM, SDL_HITTEST_RESIZE_BOTTOMLEFT, - SDL_HITTEST_RESIZE_LEFT + SDL_HITTEST_RESIZE_LEFT, + SDL_HITTEST_DRAGDATA /**< Region contains drag and drop data. */ } SDL_HitTestResult; /**