Initial drag and drop support.

This commit is contained in:
arturo
2013-07-10 11:42:14 +02:00
committed by Camilla Berglund
parent 0548c713e8
commit 89d0723ba3
10 changed files with 338 additions and 5 deletions
+37
View File
@@ -29,7 +29,9 @@
#include <stdlib.h>
#include <malloc.h>
#include <Windows.h>
#include <windowsx.h>
#include <Shellapi.h>
#define _GLFW_KEY_INVALID -2
@@ -747,6 +749,39 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// TODO: Restore vsync if compositing was disabled
break;
}
case WM_DROPFILES:
{
TCHAR szName[MAX_PATH];
HDROP hDrop = (HDROP)wParam;
POINT pt;
int numFiles = DragQueryFile(hDrop, 0xFFFFFFFF, szName, MAX_PATH);
int currentSize = 1;
int i;
char* utf8str;
DragQueryPoint(hDrop, &pt);
// Move the mouse to the position of the drop
_glfwInputCursorMotion(window,pt.x,pt.y);
memset(_glfw.win32.dropString, 0, _glfw.win32.dropStringSize);
for(i = 0; i < numFiles; i++)
{
DragQueryFile(hDrop, i, szName, MAX_PATH);
utf8str = _glfwCreateUTF8FromWideString((const wchar_t*)szName);
currentSize += strlen(utf8str);
if(_glfw.win32.dropStringSize < currentSize){
_glfw.win32.dropStringSize *= 2;
_glfw.win32.dropString = (char*)realloc(_glfw.win32.dropString,_glfw.win32.dropStringSize);
}
strcat(_glfw.win32.dropString, utf8str);
strcat(_glfw.win32.dropString, "\n");
free(utf8str);
}
_glfwInputDrop(window,_glfw.win32.dropString);
DragFinish(hDrop);
break;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
@@ -865,6 +900,8 @@ static int createWindow(_GLFWwindow* window,
window); // Pass object to WM_CREATE
free(wideTitle);
DragAcceptFiles(window->win32.handle, TRUE);
if (!window->win32.handle)
{