From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- vcl/workben/win/dnd/atlwindow.cxx | 238 +++++++++++++++++++++++++++++++++ vcl/workben/win/dnd/atlwindow.hxx | 87 ++++++++++++ vcl/workben/win/dnd/dndTest.cxx | 177 ++++++++++++++++++++++++ vcl/workben/win/dnd/makefile.mk | 70 ++++++++++ vcl/workben/win/dnd/sourcelistener.cxx | 59 ++++++++ vcl/workben/win/dnd/sourcelistener.hxx | 56 ++++++++ vcl/workben/win/dnd/targetlistener.cxx | 78 +++++++++++ vcl/workben/win/dnd/targetlistener.hxx | 64 +++++++++ vcl/workben/win/dnd/transferable.cxx | 105 +++++++++++++++ vcl/workben/win/dnd/transferable.hxx | 88 ++++++++++++ 10 files changed, 1022 insertions(+) create mode 100644 vcl/workben/win/dnd/atlwindow.cxx create mode 100644 vcl/workben/win/dnd/atlwindow.hxx create mode 100644 vcl/workben/win/dnd/dndTest.cxx create mode 100644 vcl/workben/win/dnd/makefile.mk create mode 100644 vcl/workben/win/dnd/sourcelistener.cxx create mode 100644 vcl/workben/win/dnd/sourcelistener.hxx create mode 100644 vcl/workben/win/dnd/targetlistener.cxx create mode 100644 vcl/workben/win/dnd/targetlistener.hxx create mode 100644 vcl/workben/win/dnd/transferable.cxx create mode 100644 vcl/workben/win/dnd/transferable.hxx (limited to 'vcl/workben/win/dnd') diff --git a/vcl/workben/win/dnd/atlwindow.cxx b/vcl/workben/win/dnd/atlwindow.cxx new file mode 100644 index 000000000..61781e18f --- /dev/null +++ b/vcl/workben/win/dnd/atlwindow.cxx @@ -0,0 +1,238 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "atlwindow.hxx" +#include "targetlistener.hxx" +#include "sourcelistener.hxx" +#include + +#include +using namespace com::sun::star::lang; +using namespace com::sun::star::datatransfer::dnd; +using namespace com::sun::star::datatransfer::dnd::DNDConstants; +using namespace cppu; + +LRESULT APIENTRY EditSubclassProc( HWND hwnd, UINT uMsg,WPARAM wParam, LPARAM lParam) ; + +extern Reference< XMultiServiceFactory > MultiServiceFactory; +DWORD WINAPI MTAFunc(LPVOID pParams); + +char* szSTAWin= "XDragSource::executeDrag is called from the same " + "OLE STA thread that created the window."; +char* szMTAWin= "XDragSource::executeDrag is called from an MTA thread " + "that did not create the window."; + +WNDPROC wpOrigEditProc; + +map mapEditToMainWnd; + +LRESULT AWindow::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + Reference xcompSource( m_xDragSource, UNO_QUERY); + + PostQuitMessage(0); + + m_xDropTarget=0; + m_xDragSource=0; + + // Remove the subclass from the edit control. + ::SetWindowLong(m_hwndEdit, GWL_WNDPROC, + (LONG) wpOrigEditProc); + + return 0; +} + +LRESULT AWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // Prepare the EDIT control + m_hwndEdit = CreateWindowA( + "EDIT", // predefined class + NULL, // no window title + WS_CHILD | WS_VISIBLE | WS_VSCROLL | + ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, + 0, 0, 0, 0, // set size in WM_SIZE message + m_hWnd, // parent window + (HMENU) NULL, // edit control ID + (HINSTANCE) GetWindowLong( GWL_HINSTANCE), + NULL); + + // the map is used in the window procedure for the edit window to associate the + // it to the right main window ( AWindow) + mapEditToMainWnd[m_hwndEdit]= m_hWnd; + // Superclass the edit window, because we want to process mouse messages + wpOrigEditProc = (WNDPROC) ::SetWindowLongA(m_hwndEdit, + GWL_WNDPROC, (LONG) EditSubclassProc); + + // Add text to the window. + if( m_isMTA) + ::SendMessageA(m_hwndEdit, WM_SETTEXT, 0, (LPARAM) szMTAWin); + else + ::SendMessageA(m_hwndEdit, WM_SETTEXT, 0, (LPARAM) szSTAWin); + + // create the DragSource + Reference< XInterface> xint= MultiServiceFactory->createInstance("com.sun.star.datatransfer.dnd.OleDragSource"); + m_xDragSource.set( xint, UNO_QUERY ); + Reference xInit( xint, UNO_QUERY); + + Any ar[2]; + ar[1]<<= (sal_uInt32)m_hWnd; + xInit->initialize( Sequence( ar, 2) ); + + //create the DropTarget + Reference< XInterface> xintTarget= MultiServiceFactory->createInstance("com.sun.star.datatransfer.dnd.OleDropTarget"); + m_xDropTarget.set( xintTarget, UNO_QUERY ); + Reference xInitTarget( xintTarget, UNO_QUERY); + + Any any; + any <<= (sal_uInt32)m_hWnd; + xInitTarget->initialize( Sequence( &any, 1) ); + + m_xDropTarget->addDropTargetListener( static_cast + ( new DropTargetListener( m_hwndEdit)) ); +// // make this window a drop target + m_xDropTarget->setActive(sal_True); + + return 0; +} + +// When the mouse is dragged for a second than a drag is initiated +LRESULT AWindow::OnMouseAction(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + if( uMsg== WM_LBUTTONDOWN) + { + SetTimer( 1, 1000); + } + + else if( uMsg == WM_LBUTTONUP) + { + KillTimer( 1); + } + + return 0; +} + +LRESULT AWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + USES_CONVERSION; + KillTimer( 1); + if(m_xDragSource.is()) + { + + //Get the Text out of the Edit window + int length= (int)::SendMessageA( m_hwndEdit, WM_GETTEXTLENGTH, 0, 0); + char * pBuffer= new char[length + 1]; + ZeroMemory( pBuffer, length + 1); + ::SendMessageA( m_hwndEdit, WM_GETTEXT, length, (LPARAM) pBuffer); + + IDataObject* pData= NULL; + HRESULT hr= CreateDataCache( NULL, CLSID_NULL, __uuidof(IDataObject),(void**) &pData); + if( pData) + { + FORMATETC format={ CF_TEXT, NULL, DVASPECT_CONTENT, -1, }; + + HGLOBAL mem= GlobalAlloc(GHND, length + 1 ); + void* pMem= GlobalLock( mem); + memcpy( pMem, pBuffer, length+1); + GlobalUnlock( mem); + + STGMEDIUM medium; + medium.tymed= TYMED_HGLOBAL; + medium.hGlobal= mem; + medium.pUnkForRelease= NULL; + + pData->SetData( &format, &medium, TRUE); // releases HGLOBAL eventually + + Reference xTrans= CDOTransferable::create( + MultiServiceFactory, pData); + + // call XDragSource::executeDrag from an MTA + if( m_isMTA ) + { + DWORD mtaThreadId; + ThreadData data; + data.source= m_xDragSource; + data.transferable= xTrans; + + data.evtThreadReady= CreateEvent( NULL, FALSE, FALSE, NULL); + + CloseHandle(CreateThread(NULL, 0, MTAFunc, &data, 0, &mtaThreadId)); + // We must wait until the thread copied the ThreadData structure + WaitForSingleObject( data.evtThreadReady, INFINITE); + CloseHandle( data.evtThreadReady); + + } + else + { + m_xDragSource->startDrag( DragGestureEvent(), + ACTION_LINK|ACTION_MOVE|ACTION_COPY, + 0, + 0, + xTrans, + Reference( static_cast(new DragSourceListener() ) ) ); + } + } + + delete[] pBuffer; + } + + return 0; +} + +LRESULT AWindow::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + // Make the edit control the size of the window's + // client area. + ::MoveWindow(m_hwndEdit, + 0, 0, // starting x- and y-coordinates + LOWORD(lParam), // width of client area + HIWORD(lParam), // height of client area + TRUE); // repaint window + + return 0; +} +LRESULT AWindow::OnFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) +{ + ::SetFocus(m_hwndEdit); + return 0; +} + +// Subclass procedure for EDIT window +LRESULT APIENTRY EditSubclassProc( HWND hwnd, UINT uMsg,WPARAM wParam, LPARAM lParam) +{ + + if( uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST) + { + HWND hAWindow= mapEditToMainWnd[hwnd]; + ::SendMessage( hAWindow, uMsg, wParam, lParam); + + } + return CallWindowProc( wpOrigEditProc, hwnd, uMsg, + wParam, lParam); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/atlwindow.hxx b/vcl/workben/win/dnd/atlwindow.hxx new file mode 100644 index 000000000..047acf676 --- /dev/null +++ b/vcl/workben/win/dnd/atlwindow.hxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once +#include +extern CComModule _Module; +#include +#include +#include +#include +#include +#include +#include "../../source/inc/DtObjFactory.hxx" + +using namespace com::sun::star::uno; +using namespace com::sun::star::datatransfer::dnd; +using namespace com::sun::star::datatransfer; + +struct ThreadData +{ + Reference source; + Reference transferable; + HANDLE evtThreadReady; +}; + +class AWindow: public CWindowImpl > +{ + TCHAR m_strName[80]; + Reference m_xDropTarget; + Reference m_xDragSource; + BOOL m_isMTA; + + HWND m_hwndEdit; + +public: + explicit AWindow(LPCTSTR strName) + { + RECT rcPos= {0,0,200,200}; + Create(0, rcPos, strName); + } + AWindow(LPCTSTR strName, RECT pos, BOOL mta=FALSE): m_isMTA( mta) + { + Create(0, pos, strName); + } + + ~AWindow() + { + if(m_hWnd) + DestroyWindow(); + } + + BEGIN_MSG_MAP(AWindow) + MESSAGE_HANDLER( WM_CLOSE, OnClose) + MESSAGE_HANDLER( WM_CREATE, OnCreate) + MESSAGE_RANGE_HANDLER( WM_MOUSEFIRST, WM_MOUSELAST, OnMouseAction) + MESSAGE_HANDLER( WM_TIMER, OnTimer) + MESSAGE_HANDLER( WM_SIZE, OnSize) + MESSAGE_HANDLER( WM_SETFOCUS, OnFocus) + + END_MSG_MAP() + + LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnMouseAction(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/dndTest.cxx b/vcl/workben/win/dnd/dndTest.cxx new file mode 100644 index 000000000..2f2a7bccf --- /dev/null +++ b/vcl/workben/win/dnd/dndTest.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include +#include +#include +CComModule _Module; +#include +#include +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include +#include +#include +#include +#include +#include +#include +#include "sourcelistener.hxx" + +#include "atlwindow.hxx" +BEGIN_OBJECT_MAP(ObjectMap) +END_OBJECT_MAP() + +using namespace com::sun::star::lang; +using namespace com::sun::star::datatransfer; +using namespace com::sun::star::uno; +using namespace com::sun::star::datatransfer::dnd; +using namespace com::sun::star::datatransfer::dnd::DNDConstants; + +HRESULT doTest(); +DWORD WINAPI MTAFunc( void* threadData); + +Reference< XMultiServiceFactory > MultiServiceFactory; + +int main( int argc, char *argv[ ], char *envp[ ] ) +{ + HRESULT hr; + if( FAILED( hr=CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) + { + printf("CoInitializeEx failed \n"); + return -1; + } + + _Module.Init( ObjectMap, GetModuleHandleA( NULL)); + + if( FAILED(hr=doTest())) + { + _com_error err( hr); + } + + _Module.Term(); + CoUninitialize(); + return 0; +} + +HRESULT doTest() +{ + + MultiServiceFactory= createRegistryServiceFactory( OUString(L"types.rdb"), OUString( L"services.rdb") , sal_True); + + // create the MTA thread that is used to realize MTA calls to the services + // We create the thread and wait until the thread has created its message queue + HANDLE evt= CreateEventA(NULL, FALSE, FALSE, NULL); + DWORD threadIdMTA=0; + HANDLE hMTAThread= CreateThread( NULL, 0, MTAFunc, &evt, 0, &threadIdMTA); + WaitForSingleObject( evt, INFINITE); + CloseHandle(evt); + + HRESULT hr= S_OK; + RECT pos1={0,0,300,200}; + AWindow win("DnD starting in Ole STA", threadIdMTA, pos1); + + RECT pos2={ 0, 205, 300, 405}; + AWindow win2("DnD starting in MTA", threadIdMTA, pos2, true); + + // win3 and win4 call initialize from an MTA but they are created in an STA + RECT pos3={300,0,600,200}; + AWindow win3("DnD starting in OLE STA", threadIdMTA, pos3, false, true); + + RECT pos4={ 300, 205, 600, 405}; + AWindow win24("DnD starting in Ole MTA", threadIdMTA, pos4, true, true); + + MSG msg; + while( GetMessageA(&msg, (HWND)NULL, 0, 0) ) + { + TranslateMessage( &msg); + DispatchMessageA( &msg); + } + + // Shut down the MTA thread + PostThreadMessageA( threadIdMTA, WM_QUIT, 0, 0); + WaitForSingleObject(hMTAThread, INFINITE); + CloseHandle(hMTAThread); + + return S_OK; +} + +extern Reference MultiServiceFactory; +DWORD WINAPI MTAFunc( void* threadData) +{ + HRESULT hr= CoInitializeEx( NULL, COINIT_MULTITHREADED); + ATLASSERT( FAILED(hr) ); + MSG msg; + // force the creation of a message queue + PeekMessageA(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); + SetEvent( *(HANDLE*)threadData ); + + RECT pos={0, 406, 300, 605}; + AWindow win("DnD, full MTA", GetCurrentThreadId(), pos, false, true); + + while( GetMessageA(&msg, (HWND)NULL, 0, 0) ) + { + switch( msg.message) + { + case WM_SOURCE_INIT: + { + InitializationData* pData= (InitializationData*)msg.wParam; + Any any; + any <<= (sal_uInt32) pData->hWnd; + pData->xInit->initialize( Sequence( &any, 1)); + + CoTaskMemFree( pData); + break; + } + case WM_SOURCE_STARTDRAG: + { + // wParam contains necessary data + StartDragData* pData= (StartDragData*)msg.wParam; + Sequence seq= pData->transferable->getTransferDataFlavors(); + // have a look what flavours are supported + for( int i=0; isource->startDrag( DragGestureEvent(), + ACTION_LINK|ACTION_MOVE|ACTION_COPY, + 0, + 0, + pData->transferable, + Reference( static_cast + ( new DragSourceListener()))); + CoTaskMemFree( pData); + break; + } + + } // end switch + + TranslateMessage( &msg); + DispatchMessageA( &msg); + } + + CoUninitialize(); + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/makefile.mk b/vcl/workben/win/dnd/makefile.mk new file mode 100644 index 000000000..e0d438418 --- /dev/null +++ b/vcl/workben/win/dnd/makefile.mk @@ -0,0 +1,70 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +PRJ=..$/..$/..$/ + +PRJNAME=dtrans +TARGET=dndTest +TARGETTYPE=CUI +LIBTARGET=NO + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings --- + +.INCLUDE : settings.mk + +# --- Files --- + +CFLAGS+= -D_WIN32_DCOM + +INCPRE+= -I$(ATL_INCLUDE) + +OBJFILES= $(OBJ)$/dndTest.obj \ + $(OBJ)$/atlwindow.obj \ + $(OBJ)$/targetlistener.obj \ + $(OBJ)$/sourcelistener.obj \ + $(OBJ)$/dataobject.obj + +APP1NOSAL=TRUE + +APP1TARGET= $(TARGET) +APP1OBJS=$(OBJFILES) + +APP1STDLIBS= \ + $(SALLIB) \ + $(CPPUHELPERLIB) \ + $(CPPULIB) \ + $(UWINAPILIB) \ + $(USER32LIB) \ + $(OLE32LIB) \ + comsupp.lib \ + $(OLEAUT32LIB) \ + $(GDI32LIB) \ + $(UUIDLIB) + +APP1LIBS= \ + $(SLB)$/dtobjfact.lib \ + $(SLB)$/dtutils.lib + +APP1DEF= $(MISC)\$(APP1TARGET).def + +# --- Targets --- + +.INCLUDE : target.mk + diff --git a/vcl/workben/win/dnd/sourcelistener.cxx b/vcl/workben/win/dnd/sourcelistener.cxx new file mode 100644 index 000000000..aa3366e79 --- /dev/null +++ b/vcl/workben/win/dnd/sourcelistener.cxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "sourcelistener.hxx" + +DragSourceListener::DragSourceListener() +{ +} +DragSourceListener::~DragSourceListener() +{ +} + +void SAL_CALL DragSourceListener::disposing( const EventObject& Source ) + throw(RuntimeException) +{ +} + +void SAL_CALL DragSourceListener::dragDropEnd( const DragSourceDropEvent& dsde ) + throw(RuntimeException) +{ +} + +void SAL_CALL DragSourceListener::dragEnter( const DragSourceDragEvent& dsde ) + throw(RuntimeException) +{ +} + +void SAL_CALL DragSourceListener::dragExit( const DragSourceEvent& dse ) + throw(RuntimeException) +{ +} + +void SAL_CALL DragSourceListener::dragOver( const DragSourceDragEvent& dsde ) + throw(RuntimeException) +{ +} + +void SAL_CALL DragSourceListener::dropActionChanged( const DragSourceDragEvent& dsde ) + throw(RuntimeException) +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/sourcelistener.hxx b/vcl/workben/win/dnd/sourcelistener.hxx new file mode 100644 index 000000000..0fc051399 --- /dev/null +++ b/vcl/workben/win/dnd/sourcelistener.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include +#include +#include +#include + +using namespace ::com::sun::star::datatransfer; +using namespace ::com::sun::star::datatransfer::dnd; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +class DragSourceListener: public WeakImplHelper +{ + // this is a window where dropped data are shown as text (only text) +public: + DragSourceListener( ); + ~DragSourceListener(); + + virtual void SAL_CALL disposing( const EventObject& Source ) + throw(RuntimeException); + + virtual void SAL_CALL dragDropEnd( const DragSourceDropEvent& dsde ) + throw(RuntimeException); + virtual void SAL_CALL dragEnter( const DragSourceDragEvent& dsde ) + throw(RuntimeException); + virtual void SAL_CALL dragExit( const DragSourceEvent& dse ) + throw(RuntimeException); + virtual void SAL_CALL dragOver( const DragSourceDragEvent& dsde ) + throw(RuntimeException); + virtual void SAL_CALL dropActionChanged( const DragSourceDragEvent& dsde ) + throw(RuntimeException); + +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/targetlistener.cxx b/vcl/workben/win/dnd/targetlistener.cxx new file mode 100644 index 000000000..0a93d3945 --- /dev/null +++ b/vcl/workben/win/dnd/targetlistener.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "targetlistener.hxx" +#include +#include + +using namespace com::sun::star::datatransfer::dnd::DNDConstants; +using namespace com::sun::star::datatransfer; + +DropTargetListener::DropTargetListener(HWND hEdit):m_hEdit( hEdit) +{ +} +DropTargetListener::~DropTargetListener() +{ +} + +void SAL_CALL DropTargetListener::disposing( const EventObject& Source ) + throw(RuntimeException) +{ + +} + +void SAL_CALL DropTargetListener::drop( const DropTargetDropEvent& e ) + throw(RuntimeException) +{ + e.Context->rejectDrop(); + + DataFlavor flavor( OUString(OUString("text/plain;charset=windows-1252")), + OUString(L"Text plain"), cppu::UnoType>::get() ); + + Any anyData= e.Transferable->getTransferData( flavor); + Sequence seq= *( Sequence*)anyData.getValue(); + SendMessage( m_hEdit, WM_SETTEXT, 0, (LPARAM) seq.getConstArray() ); +} + +void SAL_CALL DropTargetListener::dragEnter( const DropTargetDragEnterEvent& dtde ) + throw(RuntimeException) +{ + //If one drags something that is not moveable + if( !(dtde.SourceActions & dtde.DropAction) ) + dtde.Context->acceptDrag( ACTION_COPY); +} + +void SAL_CALL DropTargetListener::dragExit( const DropTargetEvent& dte ) + throw(RuntimeException) +{ +} + +void SAL_CALL DropTargetListener::dragOver( const DropTargetDragEvent& dtde ) + throw(RuntimeException) +{ + if( !(dtde.SourceActions & dtde.DropAction) ) + dtde.Context->acceptDrag( ACTION_COPY); +} + +void SAL_CALL DropTargetListener::dropActionChanged( const DropTargetDragEvent& dtde ) + throw(RuntimeException) +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/targetlistener.hxx b/vcl/workben/win/dnd/targetlistener.hxx new file mode 100644 index 000000000..f42fac33a --- /dev/null +++ b/vcl/workben/win/dnd/targetlistener.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include +#if defined _MSC_VER +#pragma warning(pop) +#endif +#include +#include +#include +#include +#include + +using namespace ::com::sun::star::datatransfer; +using namespace ::com::sun::star::datatransfer::dnd; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +class DropTargetListener: public WeakImplHelper +{ + // this is a window where dropped data are shown as text (only text) + HWND m_hEdit; +public: + explicit DropTargetListener(HWND hEdit); + ~DropTargetListener(); + + virtual void SAL_CALL disposing( const EventObject& Source ) + throw(RuntimeException); + + virtual void SAL_CALL drop( const DropTargetDropEvent& dtde ) + throw(RuntimeException); + virtual void SAL_CALL dragEnter( const DropTargetDragEnterEvent& dtde ) + throw(RuntimeException); + virtual void SAL_CALL dragExit( const DropTargetEvent& dte ) + throw(RuntimeException); + virtual void SAL_CALL dragOver( const DropTargetDragEvent& dtde ) + throw(RuntimeException); + virtual void SAL_CALL dropActionChanged( const DropTargetDragEvent& dtde ) + throw(RuntimeException); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/transferable.cxx b/vcl/workben/win/dnd/transferable.cxx new file mode 100644 index 000000000..924c03176 --- /dev/null +++ b/vcl/workben/win/dnd/transferable.cxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "transferable.hxx" + +// ctor + +CTransferable::CTransferable( wchar_t* dataString ) : + m_seqDFlv( 1 ), + m_Data( dataString ) +{ + DataFlavor df; + + /* + df.MimeType = L"text/plain; charset=unicode"; + df.DataType = cppu::UnoType::get(); + + m_seqDFlv[0] = df; + */ + + //df.MimeType = L"text/plain; charset=windows1252"; + df.MimeType = L"text/plain"; + df.DataType = cppu::UnoType>::get(); + + m_seqDFlv[0] = df; +} + +// getTransferData + +Any SAL_CALL CTransferable::getTransferData( const DataFlavor& aFlavor ) + throw(UnsupportedFlavorException, IOException, RuntimeException) +{ + Any anyData; + + /*if ( aFlavor == m_seqDFlv[0] ) + { + anyData = makeAny( m_Data ); + } + else*/ if ( aFlavor == m_seqDFlv[0] ) + { + OString aStr( m_Data.getStr( ), m_Data.getLength( ), 1252 ); + Sequence< sal_Int8 > sOfChars( aStr.getLength( ) ); + sal_Int32 lenStr = aStr.getLength( ); + + for ( sal_Int32 i = 0; i < lenStr; ++i ) + sOfChars[i] = aStr[i]; + + anyData = makeAny( sOfChars ); + } + + return anyData; +} + +// getTransferDataFlavors + +Sequence< DataFlavor > SAL_CALL CTransferable::getTransferDataFlavors( ) + throw(RuntimeException) +{ + return m_seqDFlv; +} + +// isDataFlavorSupported + +sal_Bool SAL_CALL CTransferable::isDataFlavorSupported( const DataFlavor& aFlavor ) + throw(RuntimeException) +{ + sal_Int32 nLength = m_seqDFlv.getLength( ); + sal_Bool bRet = sal_False; + + for ( sal_Int32 i = 0; i < nLength; ++i ) + { + if ( m_seqDFlv[i] == aFlavor ) + { + bRet = sal_True; + break; + } + } + + return bRet; +} + +// lostOwnership + +void SAL_CALL CTransferable::lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) + throw(RuntimeException) +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/workben/win/dnd/transferable.hxx b/vcl/workben/win/dnd/transferable.hxx new file mode 100644 index 000000000..c1606cab8 --- /dev/null +++ b/vcl/workben/win/dnd/transferable.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#if defined _MSC_VER +#pragma warning(push,1) +#endif +#include +#include +#if defined _MSC_VER +#pragma warning(pop) +#endif + +#include + +#include + +#include "../../source/win32/ImplHelper.hxx" + +// my defines + +#define TEST_CLIPBOARD +#define RDB_SYSPATH "d:\\projects\\src616\\dtrans\\wntmsci7\\bin\\applicat.rdb" +#define WINCLIPBOARD_SERVICE_NAME L"com.sun.star.datatransfer.clipboard.SystemClipboard" +#define WRITE_CB +#define EVT_MANUAL_RESET TRUE +#define EVT_INIT_NONSIGNALED FALSE +#define EVT_NONAME "" + +// namespaces + +using namespace ::cppu; +using namespace ::com::sun::star::datatransfer; +using namespace ::com::sun::star::datatransfer::clipboard; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; + +class CTransferable : public WeakImplHelper< XClipboardOwner, XTransferable > +{ +public: + CTransferable( ){}; + explicit CTransferable( wchar_t* dataString); + + // XTransferable + + virtual Any SAL_CALL getTransferData( const DataFlavor& aFlavor ) throw(UnsupportedFlavorException, IOException, RuntimeException); + virtual Sequence< DataFlavor > SAL_CALL getTransferDataFlavors( ) throw(RuntimeException); + virtual sal_Bool SAL_CALL isDataFlavorSupported( const DataFlavor& aFlavor ) throw(RuntimeException); + + // XClipboardOwner + + virtual void SAL_CALL lostOwnership( const Reference< XClipboard >& xClipboard, const Reference< XTransferable >& xTrans ) throw(RuntimeException); + +private: + Sequence< DataFlavor > m_seqDFlv; + OUString m_Data; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3