Hello,

I read a message from Hubert a few days ago about a French review
of Abiword, they were complaining by the lack of drag and drop text
editing and I thought that was a cool feature to add.

I have been working on adding OLE Drag and Drop support to the Windows
port.

Right now, I only have implemented the "Drop" for files (we had this before
but now it's addressed in other way) and RTF text. This allows you to drop
text from most of the applications in the market.

What is left is to add support for other formats: plain text and images,
, implement the Drag support and to show the proper cursor for every
situation.

I will keep working on these issues after the weekend.

Can someone commit the changes?

There are two new files:

abi\src\af\xap\xap_Win32DragAndDrop.h
abi\src\af\xap\xap_Win32DragAndDrop.cpp

and a diff files (diff.txt).

Best regards,

Jordi,


-- 

Jordi Mas
http://www.softcatala.org


/* AbiSource Drag and Drop
 * Copyright (C) 2002 Jordi Mas i Hern�ndez [EMAIL PROTECTED]
 * 
 * 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.
 */

#include <windows.h>
#include <richedit.h>


#include "ut_types.h"
#include "ut_string_class.h"
#include "ut_assert.h"
#include "ut_debugmsg.h"
#include "xap_Win32App.h"
#include "xap_Win32Frame.h"
#include "xav_View.h"
#include "xad_Document.h"
#include "ap_framedata.h"
#include "ie_impexp_Register.h"
#include "ie_imp.h"
#include "xap_EncodingManager.h"
#include "xap_Win32DragAndDrop.h"
#include "fl_DocLayout.h"

char szName[]="Softcatala";

STDMETHODIMP XAP_Win32DropTarget::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
{
        return S_OK;
}


STDMETHODIMP_(ULONG) XAP_Win32DropTarget::AddRef()
{
        ++m_nCount; 
        return S_OK;       
}


STDMETHODIMP_(ULONG) XAP_Win32DropTarget::Release()
{
        --m_nCount;
        return S_OK;
}

//
//      Called when the mouse first enters our DropTarget window 
//

/*
TODO:

determine what the data object contains, call the data object's 
IDataObject::EnumFormatEtc method. Use the enumerator object returned by the 
method to enumerate the formats contained by the data object. If your 
application does not want to accept any of these formats, return 
DROPEFFECT_NONE. For the purposes of this scenario, your application should 
ignore any data objects that do not contain formats used to transfer files, such 
as CF_HDROP. 
*/
STDMETHODIMP XAP_Win32DropTarget::DragEnter (LPDATAOBJECT pDataObj, DWORD grfKeyState, 
POINTL pointl, LPDWORD pdwEffect)
{
        //TODO: Check which formats we really support
        *pdwEffect = DROPEFFECT_COPY;           
        return S_OK;
}

STDMETHODIMP XAP_Win32DropTarget::DragOver  (DWORD grfKeyState, POINTL pointl, LPDWORD 
pdwEffect)
{        
        return S_OK;
}



STDMETHODIMP XAP_Win32DropTarget::DragLeave ()
{
        return S_OK;
}


//
// Called when the user drops an object
//
STDMETHODIMP XAP_Win32DropTarget::Drop (LPDATAOBJECT pDataObj, DWORD grfKeyState, 
POINTL pointl, LPDWORD pdwEffect)
{
        
        FORMATETC       formatetc;
        STGMEDIUM       medium;
        char*           pData;
        UINT            uCF_RTF;
        UT_uint32       iStrLen;
        IE_Imp*         pImp = 0;
        const char *    szEncoding = 0;
        int             count = 0;
        
        FORMATETC fmte = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
        
        //
        // Is the user dropping files?
        //
        if (NOERROR == pDataObj->QueryGetData(&fmte))
        {
                if (pDataObj && SUCCEEDED (pDataObj->GetData (&fmte, &medium)))
                        count = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 
0);
                
                // We send an event Message Window to the Win32Frame since historicaly
                // the file loading was processed there
                if (count) 
                        SendMessage(pFrame->getTopLevelWindow(), WM_DROPFILES, 
(WPARAM)medium.hGlobal, 0);      
                                
                ReleaseStgMedium(&medium);           
                return S_OK;
        }

        //
        // Is the user dropping RTF Files?
        //      
        uCF_RTF = RegisterClipboardFormat(CF_RTF);
                        
        formatetc.cfFormat = uCF_RTF;
        formatetc.ptd = NULL;
        formatetc.dwAspect  = DVASPECT_CONTENT;
        formatetc.lindex  = -1;
        formatetc.tymed = TYMED_HGLOBAL;
        
        medium.hGlobal = NULL;  
        medium.pUnkForRelease = NULL;   
      
        // TODO: Add more formats
        // Does not support RTF
        if (!SUCCEEDED(pDataObj->GetData(&formatetc, &medium)))
                return S_OK;
        
        pData = (char *) GlobalLock (medium.hGlobal);                                  
         
        iStrLen =  strlen(pData);
        
        // Get document range
        AP_FrameData* pFrameData = (AP_FrameData*) pFrame->getFrameData();
        FL_DocLayout *pDocLy =  pFrameData->m_pDocLayout;
        FV_View * pView =  pDocLy->getView();   
        PD_DocumentRange dr(pView->getDocument(),pView->getPoint(),pView->getPoint());
                        
        // Import RTF   
        IE_Imp::constructImporter(dr.m_pDoc, 0, IE_Imp::fileTypeForSuffix(".rtf"), 
&pImp, 0);
        if (pImp)
        {               
                szEncoding = 
XAP_EncodingManager::get_instance()->getNative8BitEncodingName();          
                
                //szEncoding = XAP_EncodingManager::get_instance()->getUCS2LEName();   
                         
                pImp->pasteFromBuffer(&dr, (unsigned char *)pData, iStrLen,szEncoding);
                
                delete pImp;            
                pView->_generalUpdate();
        }
        
        GlobalUnlock(medium.hGlobal);
        GlobalFree(medium.hGlobal);
        ReleaseStgMedium(&medium);              
                
        return S_OK;
}




/* AbiSource Application Framework
 * Copyright (C) 1998 AbiSource, Inc.
 * 
 * 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.
 */


#ifndef XAP_WIN32DROPTARGET_H
#define XAP_WIN32DROPTARGET_H

#include <stdlib.h>
#include <windows.h>
#include <commctrl.h>   // includes the common control header
#include <crtdbg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <iostream.h>
#include <ole2.h>

class XAP_Win32Frame;

/*****************************************************************
******************************************************************
** XAP_Win32DropTarget implements the OLE 2 Drop functionality in
** AbiWord
******************************************************************
*****************************************************************/

interface XAP_Win32DropTarget : public IDropTarget
{
        

        XAP_Win32DropTarget() {};
        ~XAP_Win32DropTarget() {};
        
        STDMETHODIMP QueryInterface (REFIID riid, LPVOID FAR* ppv);
        STDMETHODIMP_(ULONG) AddRef ();
        STDMETHODIMP_(ULONG) Release ();

        // Drap and drop methods
        STDMETHODIMP DragEnter (LPDATAOBJECT pDataObj, DWORD grfKeyState,
                        POINTL pt, LPDWORD pdwEffect);
        STDMETHODIMP DragOver  (DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
        STDMETHODIMP DragLeave ();
        STDMETHODIMP Drop (LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt,
                        LPDWORD pdwEffect);
        
        XAP_Win32Frame*         pFrame;                 
        
private:
        
        int                     m_nCount;                 // reference count

};


#endif 
Index: src/af/xap/Makefile
===================================================================
RCS file: /cvsroot/abi/src/af/xap/Makefile,v
retrieving revision 1.84
diff -u -r1.84 Makefile
--- src/af/xap/Makefile 6 May 2002 16:01:40 -0000       1.84
+++ src/af/xap/Makefile 12 Jul 2002 17:40:50 -0000
@@ -29,6 +29,7 @@
 
 PLATFORM_OBJS= $(OBJDIR)/xap_$(ABI_FE)App.$(OBJ_SUFFIX)                        \
                $(OBJDIR)/xap_$(ABI_FE)Clipboard.$(OBJ_SUFFIX)                  \
+               $(OBJDIR)/xap_$(ABI_FE)DragAndDrop.$(OBJ_SUFFIX)                       
+ \
                $(OBJDIR)/xap_$(ABI_FE)Dlg_FileOpenSaveAs.$(OBJ_SUFFIX)         \
                $(OBJDIR)/xap_$(ABI_FE)Dlg_FontChooser.$(OBJ_SUFFIX)            \
                $(OBJDIR)/xap_$(ABI_FE)Dlg_MessageBox.$(OBJ_SUFFIX)             \
Index: src/af/xap/win/Makefile
===================================================================
RCS file: /cvsroot/abi/src/af/xap/win/Makefile,v
retrieving revision 1.38
diff -u -r1.38 Makefile
--- src/af/xap/win/Makefile     27 Jan 2002 18:13:40 -0000      1.38
+++ src/af/xap/win/Makefile     12 Jul 2002 17:40:56 -0000
@@ -24,6 +24,7 @@
 
 CPPSRCS=               xap_Win32App.cpp                        \
                        xap_Win32Clipboard.cpp                  \
+                       xap_Win32DragAndDrop.cpp                \
                        xap_Win32Dlg_About.cpp                  \
                        xap_Win32Dlg_Image.cpp                  \
                        xap_Win32Dlg_ClipArt.cpp                \
Index: src/af/xap/win/xap_Win32Frame.cpp
===================================================================
RCS file: /cvsroot/abi/src/af/xap/win/xap_Win32Frame.cpp,v
retrieving revision 1.78
diff -u -r1.78 xap_Win32Frame.cpp
--- src/af/xap/win/xap_Win32Frame.cpp   4 Mar 2002 18:35:42 -0000       1.78
+++ src/af/xap/win/xap_Win32Frame.cpp   12 Jul 2002 17:41:05 -0000
@@ -42,6 +42,8 @@
 #pragma warning(disable: 4355) // 'this' used in base member initializer list
 #endif
 
+XAP_Win32DropTarget    dropTarget;
+
 // TODO Fix the following header file. It seems to be incomplete
 // TODO #include <ap_EditMethods.h>
 // TODO In the mean time, define the needed function by hand
@@ -299,11 +301,11 @@
        GetClientRect(m_hwndStatusBar,&r);
        m_iStatusBarHeight = r.bottom;
 
-       // Allow drag-and drop
-       DragAcceptFiles(m_hwndFrame, true);
-
-       // we let our caller decide when to show m_hwndFrame.
-
+       
+       // Register drag and drop data and files
+       m_dropTarget.pFrame = this;
+       RegisterDragDrop(m_hwndFrame, &m_dropTarget);   
+               
        return;
 }
 
@@ -327,6 +329,9 @@
                // if failed to get placement then invalidate stored settings
                getApp()->setGeometry(0,0,0,0,0);
        }
+       
+       RevokeDragDrop(m_hwndFrame);
+       
 
        // NOTE: this should only be called from the closeWindow edit method
        DestroyWindow(m_hwndFrame);
Index: src/af/xap/win/xap_Win32Frame.h
===================================================================
RCS file: /cvsroot/abi/src/af/xap/win/xap_Win32Frame.h,v
retrieving revision 1.39
diff -u -r1.39 xap_Win32Frame.h
--- src/af/xap/win/xap_Win32Frame.h     25 Feb 2002 14:19:11 -0000      1.39
+++ src/af/xap/win/xap_Win32Frame.h     12 Jul 2002 17:41:07 -0000
@@ -25,6 +25,7 @@
 #include "xap_Frame.h"
 #include "ut_vector.h"
 #include "xap_Win32DialogFactory.h"
+#include "xap_Win32DragAndDrop.h"
 
 class XAP_Win32App;
 class ev_Win32Keyboard;
@@ -127,6 +128,8 @@
        */
        UT_uint32                                       m_iSizeWidth;
        UT_uint32                                       m_iSizeHeight;
+               
+       XAP_Win32DropTarget                             m_dropTarget;
 };
 
 #endif /* XAP_WIN32FRAME_H */
Index: src/text/fmt/xp/fv_View.h
===================================================================
RCS file: /cvsroot/abi/src/text/fmt/xp/fv_View.h,v
retrieving revision 1.232
diff -u -r1.232 fv_View.h
--- src/text/fmt/xp/fv_View.h   12 Jul 2002 09:55:15 -0000      1.232
+++ src/text/fmt/xp/fv_View.h   12 Jul 2002 17:41:24 -0000
@@ -450,10 +450,12 @@
        bool                            isInTable();
        bool                            isInTable(PT_DocPosition pos);
        
+       void                            _generalUpdate(void);
+       
 protected:
        void                            _saveAndNotifyPieceTableChange(void);
        void                            _restorePieceTableState(void);
-       void                            _generalUpdate(void);
+       
 
        void                            _draw(UT_sint32, UT_sint32, UT_sint32, 
UT_sint32, bool bDirtyRunsOnly, bool bClip=false);
 
Index: src/wp/ap/win/ap_Win32App.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/win/ap_Win32App.cpp,v
retrieving revision 1.90
diff -u -r1.90 ap_Win32App.cpp
--- src/wp/ap/win/ap_Win32App.cpp       23 May 2002 20:31:00 -0000      1.90
+++ src/wp/ap/win/ap_Win32App.cpp       12 Jul 2002 17:41:46 -0000
@@ -34,6 +34,7 @@
 #include <io.h>
 #include <fcntl.h>
 #include <iostream.h>
+#include <ole2.h>
 
 #include "ut_debugmsg.h"
 #include "ut_bytebuf.h"
@@ -521,6 +522,7 @@
                        : strlen(reinterpret_cast<const char *>(pData));
                UT_uint32 iLen = MyMin(iSize,iStrLen);
 
+               
                IE_Imp * pImp = 0;
                IE_Imp::constructImporter(pDocRange->m_pDoc, 0, 
IE_Imp::fileTypeForSuffix(szType), &pImp, 0);
                if (pImp)
@@ -738,7 +740,8 @@
        bool bShowApp = true;
        bool bShowSplash = true;
        bool bSplashPref = true;
-
+       BOOL bInitialized; 
+       
        // this is a static function and doesn't have a 'this' pointer.
        MSG msg;
 
@@ -785,6 +788,11 @@
        
        AP_Win32App * pMyWin32App;
 
+       // OLE Stuff
+       if (SUCCEEDED(OleInitialize(NULL)))
+            bInitialized = TRUE;                    
+  
+       
 // We put this in a block to force the destruction of Args in the stack
 {      
        // Load the command line into an XAP_Args class
@@ -874,6 +882,10 @@
                        }
            }
        }
+       
+       // Un-init OLE                         
+        if (bInitialized)
+                OleUninitialize();
        
        // Step 4: Destroy the App.  It should take care of deleting all frames.
        pMyWin32App->shutdown();
Index: src/wp/main/win/Makefile
===================================================================
RCS file: /cvsroot/abi/src/wp/main/win/Makefile,v
retrieving revision 1.37
diff -u -r1.37 Makefile
--- src/wp/main/win/Makefile    15 Jun 2002 22:46:30 -0000      1.37
+++ src/wp/main/win/Makefile    12 Jul 2002 17:41:56 -0000
@@ -40,7 +40,7 @@
 ####ABI_LIBS=          kernel32 user32 gdi32 winspool comdlg32 advapi32 \
 ####                   shell32 ole32 oleaut32 uuid odbc32 odbccp32
 ABI_LIBS=              kernel32 user32 gdi32 winspool comdlg32 advapi32 \
-                       shell32 uuid comctl32 msvcprt
+                       shell32 uuid comctl32 msvcprt ole32
 
 ifeq ($(ABI_OPT_CURLHASH),1)
 ABI_APPLIBS+=  Abi_libcurl

Reply via email to