2001-09-29 19:57:32 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
2001-09-29 19:57:32 +04:00
|
|
|
//
|
|
|
|
// Drag & Drop code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 21:18:27 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
2001-09-29 19:57:32 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2010-04-28 07:15:47 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
2001-09-29 19:57:32 +04:00
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
// This file contains win32-specific code for fltk which is always linked
|
|
|
|
// in. Search other files for "WIN32" or filenames ending in _win32.cxx
|
|
|
|
// for other system-specific code.
|
2001-09-29 19:57:32 +04:00
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
#include <FL/Fl.H>
|
2002-06-07 20:37:48 +04:00
|
|
|
#include <FL/x.H>
|
2002-02-24 20:52:18 +03:00
|
|
|
#include <FL/Fl_Window.H>
|
2008-09-19 21:40:20 +04:00
|
|
|
#include <FL/fl_utf8.h>
|
2002-04-11 15:52:43 +04:00
|
|
|
#include "flstring.h"
|
2002-02-24 20:52:18 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
2008-09-11 03:56:49 +04:00
|
|
|
#include <objidl.h>
|
2002-02-24 20:52:18 +03:00
|
|
|
#include <time.h>
|
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2001-09-29 19:57:32 +04:00
|
|
|
|
2002-03-25 22:17:05 +03:00
|
|
|
extern char *fl_selection_buffer[2];
|
|
|
|
extern int fl_selection_length[2];
|
|
|
|
extern int fl_selection_buffer_length[2];
|
|
|
|
extern char fl_i_own_selection[2];
|
2008-09-11 03:56:49 +04:00
|
|
|
extern char *fl_locale2utf8(const char *s, UINT codepage = 0);
|
|
|
|
extern unsigned int fl_codepage;
|
2002-02-24 20:52:18 +03:00
|
|
|
|
|
|
|
Fl_Window *fl_dnd_target_window = 0;
|
|
|
|
|
2002-04-10 19:01:22 +04:00
|
|
|
#include <ole2.h>
|
2003-05-05 01:45:46 +04:00
|
|
|
#include <shellapi.h>
|
2008-09-11 03:56:49 +04:00
|
|
|
#include <shlobj.h>
|
|
|
|
|
2002-04-10 19:01:22 +04:00
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
/**
|
|
|
|
* subclass the IDropTarget to receive data from DnD operations
|
|
|
|
*/
|
|
|
|
class FLDropTarget : public IDropTarget
|
|
|
|
{
|
|
|
|
DWORD m_cRefCount;
|
|
|
|
DWORD lastEffect;
|
|
|
|
int px, py;
|
|
|
|
public:
|
|
|
|
FLDropTarget() : m_cRefCount(0) { } // initialize
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, LPVOID *ppvObject ) {
|
|
|
|
if (IID_IUnknown==riid || IID_IDropTarget==riid)
|
|
|
|
{
|
|
|
|
*ppvObject=this;
|
|
|
|
((LPUNKNOWN)*ppvObject)->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef() { return ++m_cRefCount; }
|
|
|
|
ULONG STDMETHODCALLTYPE Release() {
|
|
|
|
long nTemp;
|
|
|
|
nTemp = --m_cRefCount;
|
|
|
|
if(nTemp==0)
|
|
|
|
delete this;
|
|
|
|
return nTemp;
|
|
|
|
}
|
2002-06-29 04:10:05 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE DragEnter( IDataObject *pDataObj, DWORD /*grfKeyState*/, POINTL pt, DWORD *pdwEffect) {
|
2002-02-24 20:52:18 +03:00
|
|
|
if( !pDataObj ) return E_INVALIDARG;
|
|
|
|
// set e_modifiers here from grfKeyState, set e_x and e_root_x
|
|
|
|
// check if FLTK handles this drag and return if it can't (i.e. BMP drag without filename)
|
2008-09-11 03:56:49 +04:00
|
|
|
POINT ppt;
|
|
|
|
Fl::e_x_root = ppt.x = pt.x;
|
2002-02-24 20:52:18 +03:00
|
|
|
Fl::e_y_root = ppt.y = pt.y;
|
|
|
|
HWND hWnd = WindowFromPoint( ppt );
|
|
|
|
Fl_Window *target = fl_find( hWnd );
|
|
|
|
if (target) {
|
|
|
|
Fl::e_x = Fl::e_x_root-target->x();
|
|
|
|
Fl::e_y = Fl::e_y_root-target->y();
|
|
|
|
}
|
|
|
|
fl_dnd_target_window = target;
|
|
|
|
px = pt.x; py = pt.y;
|
2005-08-15 23:18:49 +04:00
|
|
|
if (fillCurrentDragData(pDataObj)) {
|
2002-02-24 20:52:18 +03:00
|
|
|
// FLTK has no mechanism yet for the different drop effects, so we allow move and copy
|
2005-08-15 23:18:49 +04:00
|
|
|
if ( target && Fl::handle( FL_DND_ENTER, target ) )
|
|
|
|
*pdwEffect = DROPEFFECT_MOVE|DROPEFFECT_COPY; //|DROPEFFECT_LINK;
|
|
|
|
else
|
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
} else {
|
2002-02-24 20:52:18 +03:00
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
2005-08-15 23:18:49 +04:00
|
|
|
}
|
2002-02-24 20:52:18 +03:00
|
|
|
lastEffect = *pdwEffect;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-29 04:10:05 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE DragOver( DWORD /*grfKeyState*/, POINTL pt, DWORD *pdwEffect) {
|
2008-09-11 03:56:49 +04:00
|
|
|
if ( px==pt.x && py==pt.y )
|
2002-02-24 20:52:18 +03:00
|
|
|
{
|
|
|
|
*pdwEffect = lastEffect;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
if ( !fl_dnd_target_window )
|
|
|
|
{
|
|
|
|
*pdwEffect = lastEffect = DROPEFFECT_NONE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
// set e_modifiers here from grfKeyState, set e_x and e_root_x
|
2008-09-11 03:56:49 +04:00
|
|
|
Fl::e_x_root = pt.x;
|
2002-02-24 20:52:18 +03:00
|
|
|
Fl::e_y_root = pt.y;
|
|
|
|
if (fl_dnd_target_window) {
|
|
|
|
Fl::e_x = Fl::e_x_root-fl_dnd_target_window->x();
|
|
|
|
Fl::e_y = Fl::e_y_root-fl_dnd_target_window->y();
|
|
|
|
}
|
2005-08-15 23:18:49 +04:00
|
|
|
if (fillCurrentDragData(0)) {
|
|
|
|
// Fl_Group will change DND_DRAG into DND_ENTER and DND_LEAVE if needed
|
|
|
|
if ( Fl::handle( FL_DND_DRAG, fl_dnd_target_window ) )
|
|
|
|
*pdwEffect = DROPEFFECT_MOVE|DROPEFFECT_COPY; //|DROPEFFECT_LINK;
|
2008-09-11 03:56:49 +04:00
|
|
|
else
|
2005-08-15 23:18:49 +04:00
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
|
|
|
} else {
|
2002-02-24 20:52:18 +03:00
|
|
|
*pdwEffect = DROPEFFECT_NONE;
|
2005-08-15 23:18:49 +04:00
|
|
|
}
|
2002-02-24 20:52:18 +03:00
|
|
|
px = pt.x; py = pt.y;
|
|
|
|
lastEffect = *pdwEffect;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
HRESULT STDMETHODCALLTYPE DragLeave() {
|
2005-08-15 23:18:49 +04:00
|
|
|
if ( fl_dnd_target_window && fillCurrentDragData(0))
|
2002-02-24 20:52:18 +03:00
|
|
|
{
|
|
|
|
Fl::handle( FL_DND_LEAVE, fl_dnd_target_window );
|
|
|
|
fl_dnd_target_window = 0;
|
2005-08-15 23:18:49 +04:00
|
|
|
clearCurrentDragData();
|
2002-02-24 20:52:18 +03:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
2002-06-29 04:10:05 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE Drop( IDataObject *data, DWORD /*grfKeyState*/, POINTL pt, DWORD* /*pdwEffect*/) {
|
2002-02-24 20:52:18 +03:00
|
|
|
if ( !fl_dnd_target_window )
|
|
|
|
return S_OK;
|
|
|
|
Fl_Window *target = fl_dnd_target_window;
|
|
|
|
fl_dnd_target_window = 0;
|
2008-09-11 03:56:49 +04:00
|
|
|
Fl::e_x_root = pt.x;
|
2002-02-24 20:52:18 +03:00
|
|
|
Fl::e_y_root = pt.y;
|
|
|
|
if (target) {
|
|
|
|
Fl::e_x = Fl::e_x_root-target->x();
|
|
|
|
Fl::e_y = Fl::e_y_root-target->y();
|
|
|
|
}
|
|
|
|
// tell FLTK that the user released an object on this widget
|
|
|
|
if ( !Fl::handle( FL_DND_RELEASE, target ) )
|
|
|
|
return S_OK;
|
2008-09-11 03:56:49 +04:00
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
Fl_Widget *w = target;
|
|
|
|
while (w->parent()) w = w->window();
|
|
|
|
HWND hwnd = fl_xid( (Fl_Window*)w );
|
2005-08-15 23:18:49 +04:00
|
|
|
if (fillCurrentDragData(data)) {
|
|
|
|
int old_event = Fl::e_number;
|
2010-12-10 20:52:14 +03:00
|
|
|
char *a, *b;
|
|
|
|
a = b = Fl::e_text;
|
|
|
|
while (*a) { // strip the CRLF pairs
|
|
|
|
if (*a == '\r' && a[1] == '\n') a++;
|
|
|
|
else *b++ = *a++;
|
|
|
|
}
|
|
|
|
*b = 0;
|
|
|
|
Fl::e_length = b - Fl::e_text;
|
2005-08-15 23:18:49 +04:00
|
|
|
Fl::belowmouse()->handle(Fl::e_number = FL_PASTE); // e_text will be invalid after this call
|
|
|
|
Fl::e_number = old_event;
|
|
|
|
SetForegroundWindow( hwnd );
|
|
|
|
clearCurrentDragData();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
static IDataObject *currDragRef;
|
|
|
|
static char *currDragData;
|
2008-09-11 03:56:49 +04:00
|
|
|
static int currDragSize;
|
2005-08-15 23:18:49 +04:00
|
|
|
static char currDragResult;
|
|
|
|
|
|
|
|
static void clearCurrentDragData() {
|
|
|
|
currDragRef = 0;
|
|
|
|
if (currDragData) free(currDragData);
|
|
|
|
currDragData = 0;
|
|
|
|
currDragSize = 0;
|
|
|
|
currDragResult = 0;
|
|
|
|
}
|
|
|
|
static char fillCurrentDragData(IDataObject *data) {
|
|
|
|
// shortcut through this whole procedure if there is no fresh data
|
|
|
|
if (!data)
|
|
|
|
return currDragResult;
|
|
|
|
// shortcut through this whole procedure if this is still the same drag event
|
|
|
|
// (* this is safe, because 'currDragRef' is cleared on Leave and Drop events)
|
|
|
|
if (data==currDragRef)
|
|
|
|
return currDragResult;
|
2002-02-24 20:52:18 +03:00
|
|
|
|
2005-08-15 23:18:49 +04:00
|
|
|
// clear currDrag* for a new drag event
|
|
|
|
clearCurrentDragData();
|
|
|
|
|
|
|
|
// fill currDrag* with ASCII data, if available
|
2002-02-24 20:52:18 +03:00
|
|
|
FORMATETC fmt = { 0 };
|
|
|
|
STGMEDIUM medium = { 0 };
|
|
|
|
fmt.tymed = TYMED_HGLOBAL;
|
|
|
|
fmt.dwAspect = DVASPECT_CONTENT;
|
|
|
|
fmt.lindex = -1;
|
2010-12-13 00:49:54 +03:00
|
|
|
fmt.cfFormat = CF_UNICODETEXT;
|
|
|
|
// if it is UNICODE text, return a UTF-8-converted copy of it
|
|
|
|
if ( data->GetData( &fmt, &medium )==S_OK )
|
|
|
|
{
|
|
|
|
void *stuff = GlobalLock( medium.hGlobal );
|
|
|
|
unsigned srclen = 0;
|
|
|
|
const wchar_t *wstuff = (const wchar_t *)stuff;
|
|
|
|
while(*wstuff++) srclen++;
|
|
|
|
wstuff = (const wchar_t *)stuff;
|
|
|
|
unsigned utf8len = fl_utf8fromwc(NULL, 0, wstuff, srclen);
|
|
|
|
Fl::e_length = utf8len;
|
|
|
|
Fl::e_text = (char*)malloc(utf8len + 1);
|
|
|
|
fl_utf8fromwc(Fl::e_text, Fl::e_length, wstuff, srclen);
|
|
|
|
GlobalUnlock( medium.hGlobal );
|
|
|
|
ReleaseStgMedium( &medium );
|
|
|
|
currDragResult = 1;
|
|
|
|
return currDragResult;
|
|
|
|
}
|
2002-02-24 20:52:18 +03:00
|
|
|
fmt.cfFormat = CF_TEXT;
|
2010-12-13 00:49:54 +03:00
|
|
|
// if it is CP1252 text, return a UTF-8-converted copy of it
|
2002-02-24 20:52:18 +03:00
|
|
|
if ( data->GetData( &fmt, &medium )==S_OK )
|
|
|
|
{
|
2010-12-13 00:49:54 +03:00
|
|
|
int len;
|
|
|
|
char *p, *q, *last;
|
|
|
|
unsigned u;
|
2002-02-24 20:52:18 +03:00
|
|
|
void *stuff = GlobalLock( medium.hGlobal );
|
2010-12-13 00:49:54 +03:00
|
|
|
Fl::e_text = (char*)malloc(3 * strlen((char*)stuff) + 10);
|
|
|
|
p = (char*)stuff;
|
|
|
|
last = p + strlen(p);
|
|
|
|
q = Fl::e_text;
|
|
|
|
while (p < last) {
|
|
|
|
u = fl_utf8decode(p, last, &len);
|
|
|
|
p += len;
|
|
|
|
len = fl_utf8encode(u, q);
|
|
|
|
q += len;
|
|
|
|
}
|
|
|
|
*q = 0;
|
|
|
|
Fl::e_length = q - Fl::e_text;
|
|
|
|
Fl::e_text = (char*)realloc(Fl::e_text, Fl::e_length + 1);
|
2002-02-24 20:52:18 +03:00
|
|
|
GlobalUnlock( medium.hGlobal );
|
|
|
|
ReleaseStgMedium( &medium );
|
2005-08-15 23:18:49 +04:00
|
|
|
currDragResult = 1;
|
|
|
|
return currDragResult;
|
2002-02-24 20:52:18 +03:00
|
|
|
}
|
2005-08-15 23:18:49 +04:00
|
|
|
// else fill currDrag* with filenames, if possible
|
|
|
|
memset(&fmt, 0, sizeof(fmt));
|
2002-02-24 20:52:18 +03:00
|
|
|
fmt.tymed = TYMED_HGLOBAL;
|
|
|
|
fmt.dwAspect = DVASPECT_CONTENT;
|
|
|
|
fmt.lindex = -1;
|
|
|
|
fmt.cfFormat = CF_HDROP;
|
2008-12-13 21:31:54 +03:00
|
|
|
// if it is a pathname list, send an FL_PASTE with a \n separated list of filepaths
|
2002-02-24 20:52:18 +03:00
|
|
|
if ( data->GetData( &fmt, &medium )==S_OK )
|
|
|
|
{
|
|
|
|
HDROP hdrop = (HDROP)medium.hGlobal;
|
2008-09-11 03:56:49 +04:00
|
|
|
int i, n, nn = 0, nf = DragQueryFileW( hdrop, (UINT)-1, 0, 0 );
|
|
|
|
for ( i=0; i<nf; i++ ) nn += DragQueryFileW( hdrop, i, 0, 0 );
|
2002-02-24 20:52:18 +03:00
|
|
|
nn += nf;
|
2008-09-11 03:56:49 +04:00
|
|
|
xchar *dst = (xchar *)malloc(nn * sizeof(xchar));
|
|
|
|
xchar *bu = dst;
|
2002-02-24 20:52:18 +03:00
|
|
|
for ( i=0; i<nf; i++ ) {
|
2008-09-11 03:56:49 +04:00
|
|
|
n = DragQueryFileW( hdrop, i, (WCHAR*)dst, nn );
|
|
|
|
dst += n;
|
|
|
|
if ( i<nf-1 ) {
|
|
|
|
*dst++ = L'\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*dst=0;
|
|
|
|
|
|
|
|
Fl::e_text = (char*) malloc(nn * 5 + 1);
|
|
|
|
// Fl::e_length = fl_unicode2utf(bu, nn, Fl::e_text);
|
|
|
|
Fl::e_length = fl_utf8fromwc(Fl::e_text, (nn*5+1), bu, nn);
|
|
|
|
Fl::e_text[Fl::e_length] = 0;
|
|
|
|
free(bu);
|
|
|
|
|
|
|
|
// Fl::belowmouse()->handle(FL_DROP);
|
|
|
|
// free( Fl::e_text );
|
2002-02-24 20:52:18 +03:00
|
|
|
ReleaseStgMedium( &medium );
|
2005-08-15 23:18:49 +04:00
|
|
|
currDragResult = 1;
|
|
|
|
return currDragResult;
|
2002-02-24 20:52:18 +03:00
|
|
|
}
|
2005-08-15 23:18:49 +04:00
|
|
|
currDragResult = 0;
|
|
|
|
return currDragResult;
|
2002-02-24 20:52:18 +03:00
|
|
|
}
|
|
|
|
} flDropTarget;
|
|
|
|
|
2002-05-02 00:05:19 +04:00
|
|
|
IDropTarget *flIDropTarget = &flDropTarget;
|
|
|
|
|
2005-08-15 23:18:49 +04:00
|
|
|
IDataObject *FLDropTarget::currDragRef = 0;
|
|
|
|
char *FLDropTarget::currDragData = 0;
|
2008-09-11 03:56:49 +04:00
|
|
|
int FLDropTarget::currDragSize = 0;
|
2005-08-15 23:18:49 +04:00
|
|
|
char FLDropTarget::currDragResult = 0;
|
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
/**
|
|
|
|
* this class is needed to allow FLTK apps to be a DnD source
|
|
|
|
*/
|
|
|
|
class FLDropSource : public IDropSource
|
|
|
|
{
|
|
|
|
DWORD m_cRefCount;
|
|
|
|
public:
|
|
|
|
FLDropSource() { m_cRefCount = 0; }
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, LPVOID *ppvObject ) {
|
|
|
|
if (IID_IUnknown==riid || IID_IDropSource==riid)
|
|
|
|
{
|
|
|
|
*ppvObject=this;
|
|
|
|
((LPUNKNOWN)*ppvObject)->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef() { return ++m_cRefCount; }
|
|
|
|
ULONG STDMETHODCALLTYPE Release() {
|
|
|
|
long nTemp;
|
|
|
|
nTemp = --m_cRefCount;
|
|
|
|
if(nTemp==0)
|
|
|
|
delete this;
|
|
|
|
return nTemp;
|
|
|
|
}
|
|
|
|
STDMETHODIMP GiveFeedback( ulong ) { return DRAGDROP_S_USEDEFAULTCURSORS; }
|
2008-09-11 03:56:49 +04:00
|
|
|
STDMETHODIMP QueryContinueDrag( BOOL esc, DWORD keyState ) {
|
|
|
|
if ( esc )
|
2002-02-24 20:52:18 +03:00
|
|
|
return DRAGDROP_S_CANCEL;
|
2008-09-11 03:56:49 +04:00
|
|
|
if ( !(keyState & (MK_LBUTTON|MK_MBUTTON|MK_RBUTTON)) )
|
2002-02-24 20:52:18 +03:00
|
|
|
return DRAGDROP_S_DROP;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
};
|
2008-09-11 03:56:49 +04:00
|
|
|
class FLEnum : public IEnumFORMATETC
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int n;
|
|
|
|
LONG m_lRefCount;
|
|
|
|
|
|
|
|
ULONG __stdcall AddRef(void) {
|
|
|
|
return InterlockedIncrement(&m_lRefCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG __stdcall Release(void) {
|
|
|
|
LONG count = InterlockedDecrement(&m_lRefCount);
|
|
|
|
if(count == 0) {
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT __stdcall QueryInterface(REFIID iid, void **ppvObject) {
|
|
|
|
if(iid == IID_IEnumFORMATETC || iid == IID_IUnknown) {
|
|
|
|
AddRef();
|
|
|
|
*ppvObject = this;
|
|
|
|
return S_OK;
|
|
|
|
} else {
|
|
|
|
*ppvObject = 0;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall Next(ULONG celt, FORMATETC * rgelt, ULONG *pceltFetched) {
|
|
|
|
if (n > 0) return S_FALSE;
|
|
|
|
for (ULONG i = 0; i < celt; i++) {
|
|
|
|
n++;
|
|
|
|
rgelt->cfFormat = CF_HDROP;
|
|
|
|
rgelt->dwAspect = DVASPECT_CONTENT;
|
|
|
|
rgelt->lindex = -1;
|
|
|
|
rgelt->ptd = NULL;
|
|
|
|
rgelt->tymed = TYMED_HGLOBAL;
|
|
|
|
}
|
|
|
|
if (pceltFetched) *pceltFetched = celt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall Skip(ULONG celt) {
|
|
|
|
n += celt;
|
|
|
|
return (n == 0) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall Reset(void) {
|
|
|
|
n = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall Clone(IEnumFORMATETC **ppenum){
|
|
|
|
*ppenum = new FLEnum();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FLEnum(void) {
|
|
|
|
m_lRefCount = 1;
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-11 14:15:18 +03:00
|
|
|
virtual ~FLEnum(void) {
|
2008-09-11 03:56:49 +04:00
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-09-29 19:57:32 +04:00
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
/**
|
2008-12-07 20:01:55 +03:00
|
|
|
This is the actual object that FLTK can drop somewhere.
|
|
|
|
|
|
|
|
The implementation is minimal, but it should work with all decent Win32 drop targets
|
|
|
|
*/
|
2002-02-24 20:52:18 +03:00
|
|
|
class FLDataObject : public IDataObject
|
|
|
|
{
|
|
|
|
DWORD m_cRefCount;
|
2008-09-11 03:56:49 +04:00
|
|
|
FLEnum *m_EnumF;
|
2002-02-24 20:52:18 +03:00
|
|
|
public:
|
2008-09-11 03:56:49 +04:00
|
|
|
FLDataObject() { m_cRefCount = 1; }// m_EnumF = new FLEnum();}
|
2002-02-24 20:52:18 +03:00
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, LPVOID *ppvObject ) {
|
|
|
|
if (IID_IUnknown==riid || IID_IDataObject==riid)
|
|
|
|
{
|
|
|
|
*ppvObject=this;
|
|
|
|
((LPUNKNOWN)*ppvObject)->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef() { return ++m_cRefCount; }
|
|
|
|
ULONG STDMETHODCALLTYPE Release() {
|
|
|
|
long nTemp;
|
|
|
|
nTemp = --m_cRefCount;
|
|
|
|
if(nTemp==0)
|
|
|
|
delete this;
|
|
|
|
return nTemp;
|
|
|
|
}
|
2010-12-11 19:25:59 +03:00
|
|
|
// GetData currently allows UNICODE text through Global Memory only
|
2002-02-24 20:52:18 +03:00
|
|
|
HRESULT STDMETHODCALLTYPE GetData( FORMATETC *pformatetcIn, STGMEDIUM *pmedium ) {
|
|
|
|
if ((pformatetcIn->dwAspect & DVASPECT_CONTENT) &&
|
|
|
|
(pformatetcIn->tymed & TYMED_HGLOBAL) &&
|
2010-12-11 19:25:59 +03:00
|
|
|
(pformatetcIn->cfFormat == CF_UNICODETEXT))
|
2002-02-24 20:52:18 +03:00
|
|
|
{
|
2010-12-11 19:25:59 +03:00
|
|
|
int utf16_len = fl_utf8toUtf16(fl_selection_buffer[0], fl_selection_length[0], 0, 0);
|
|
|
|
HGLOBAL gh = GlobalAlloc( GHND, utf16_len * 2 + 2 );
|
2002-02-24 20:52:18 +03:00
|
|
|
char *pMem = (char*)GlobalLock( gh );
|
2010-12-12 00:41:42 +03:00
|
|
|
fl_utf8toUtf16(fl_selection_buffer[0], fl_selection_length[0], (unsigned short*)pMem, utf16_len + 1);
|
2008-09-11 03:56:49 +04:00
|
|
|
// HGLOBAL gh = GlobalAlloc( GHND| GMEM_SHARE,
|
|
|
|
// (fl_selection_length[0]+4) * sizeof(short)
|
|
|
|
// + sizeof(DROPFILES));
|
|
|
|
// unsigned char *pMem = (unsigned char*)GlobalLock( gh );
|
|
|
|
// if (!pMem) {
|
|
|
|
// GlobalFree(gh);
|
|
|
|
// return DV_E_FORMATETC;
|
|
|
|
// }
|
|
|
|
// DROPFILES *df =(DROPFILES*) pMem;
|
|
|
|
// int l;
|
|
|
|
// df->pFiles = sizeof(DROPFILES);
|
|
|
|
// df->pt.x = 0;
|
|
|
|
// df->pt.y = 0;
|
|
|
|
// df->fNC = FALSE;
|
|
|
|
// for (int i = 0; i < fl_selection_length[0]; i++) {
|
|
|
|
// if (fl_selection_buffer[0][i] == '\n') {
|
|
|
|
// fl_selection_buffer[0][i] = '\0';
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// df->fWide = TRUE;
|
|
|
|
// l = fl_utf2unicode((unsigned char*)fl_selection_buffer[0],
|
|
|
|
// fl_selection_length[0], (xchar*)(((char*)pMem)
|
|
|
|
// + sizeof(DROPFILES)));
|
|
|
|
//
|
|
|
|
// pMem[l * sizeof(WCHAR) + sizeof(DROPFILES)] = 0;
|
|
|
|
// pMem[l * sizeof(WCHAR) + 1 + sizeof(DROPFILES)] = 0;
|
|
|
|
// pMem[l * sizeof(WCHAR) + 2 + sizeof(DROPFILES)] = 0;
|
|
|
|
// pMem[l * sizeof(WCHAR) + 3 + sizeof(DROPFILES)] = 0;
|
2002-02-24 20:52:18 +03:00
|
|
|
pmedium->tymed = TYMED_HGLOBAL;
|
|
|
|
pmedium->hGlobal = gh;
|
|
|
|
pmedium->pUnkForRelease = NULL;
|
|
|
|
GlobalUnlock( gh );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return DV_E_FORMATETC;
|
|
|
|
}
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryGetData( FORMATETC *pformatetc )
|
|
|
|
{
|
|
|
|
if ((pformatetc->dwAspect & DVASPECT_CONTENT) &&
|
|
|
|
(pformatetc->tymed & TYMED_HGLOBAL) &&
|
2010-12-11 19:25:59 +03:00
|
|
|
(pformatetc->cfFormat == CF_UNICODETEXT))
|
2002-02-24 20:52:18 +03:00
|
|
|
return S_OK;
|
2008-09-11 03:56:49 +04:00
|
|
|
return DV_E_FORMATETC;
|
|
|
|
}
|
|
|
|
// HRESULT STDMETHODCALLTYPE EnumFormatEtc( DWORD dir, IEnumFORMATETC** ppenumFormatEtc) {
|
|
|
|
// *ppenumFormatEtc = m_EnumF;
|
|
|
|
// return S_OK;
|
|
|
|
// }
|
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
// all the following methods are not really needed for a DnD object
|
2002-06-29 04:10:05 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE GetDataHere( FORMATETC* /*pformatetcIn*/, STGMEDIUM* /*pmedium*/) { return E_NOTIMPL; }
|
|
|
|
HRESULT STDMETHODCALLTYPE GetCanonicalFormatEtc( FORMATETC* /*in*/, FORMATETC* /*out*/) { return E_NOTIMPL; }
|
|
|
|
HRESULT STDMETHODCALLTYPE SetData( FORMATETC* /*pformatetc*/, STGMEDIUM* /*pmedium*/, BOOL /*fRelease*/) { return E_NOTIMPL; }
|
|
|
|
HRESULT STDMETHODCALLTYPE EnumFormatEtc( DWORD /*dir*/, IEnumFORMATETC** /*ppenumFormatEtc*/) { return E_NOTIMPL; }
|
2008-09-11 03:56:49 +04:00
|
|
|
// HRESULT STDMETHODCALLTYPE EnumFormatEtc( DWORD dir, IEnumFORMATETC** ppenumFormatEtc) {*ppenumFormatEtc = m_EnumF; return S_OK;}
|
2002-06-29 04:10:05 +04:00
|
|
|
HRESULT STDMETHODCALLTYPE DAdvise( FORMATETC* /*pformatetc*/, DWORD /*advf*/,
|
|
|
|
IAdviseSink* /*pAdvSink*/, DWORD* /*pdwConnection*/) { return E_NOTIMPL; }
|
|
|
|
HRESULT STDMETHODCALLTYPE DUnadvise( DWORD /*dwConnection*/) { return E_NOTIMPL; }
|
|
|
|
HRESULT STDMETHODCALLTYPE EnumDAdvise( IEnumSTATDATA** /*ppenumAdvise*/) { return E_NOTIMPL; }
|
2002-02-24 20:52:18 +03:00
|
|
|
};
|
2001-09-29 19:57:32 +04:00
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
|
|
|
|
int Fl::dnd()
|
|
|
|
{
|
|
|
|
DWORD dropEffect;
|
|
|
|
ReleaseCapture();
|
|
|
|
|
|
|
|
FLDataObject *fdo = new FLDataObject;
|
|
|
|
fdo->AddRef();
|
|
|
|
FLDropSource *fds = new FLDropSource;
|
|
|
|
fds->AddRef();
|
|
|
|
|
|
|
|
HRESULT ret = DoDragDrop( fdo, fds, DROPEFFECT_MOVE|DROPEFFECT_LINK|DROPEFFECT_COPY, &dropEffect );
|
|
|
|
|
|
|
|
fdo->Release();
|
|
|
|
fds->Release();
|
|
|
|
|
|
|
|
Fl_Widget *w = Fl::pushed();
|
|
|
|
if ( w )
|
|
|
|
{
|
2004-12-03 06:14:17 +03:00
|
|
|
int old_event = Fl::e_number;
|
|
|
|
w->handle(Fl::e_number = FL_RELEASE);
|
|
|
|
Fl::e_number = old_event;
|
2002-02-24 20:52:18 +03:00
|
|
|
Fl::pushed( 0 );
|
|
|
|
}
|
2002-04-10 00:36:28 +04:00
|
|
|
if ( ret==DRAGDROP_S_DROP ) return 1; // or DD_S_CANCEL
|
|
|
|
return 0;
|
|
|
|
}
|
2001-09-29 19:57:32 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
2001-09-29 19:57:32 +04:00
|
|
|
//
|