Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GDragAndDrop.h

Go to the documentation of this file.
00001 
00002 
00003 #ifndef __DRAG_AND_DROP
00004 #define __DRAG_AND_DROP
00005 
00006 #include "GVariant.h"
00007 
00008 #if defined WIN32
00009 
00010 #include <shlobj.h>
00011 #include "GCom.h"
00012 
00013 #else
00014 
00015 #define S_OK                                0
00016 #define DROPEFFECT_NONE                     0x0
00017 #define DROPEFFECT_COPY                     0x1
00018 #define DROPEFFECT_MOVE                     0x2
00019 #define DROPEFFECT_LINK                     0x4
00020 
00021 #endif
00022 
00023 // int <-> char* format conversions
00024 #if defined WIN32
00025 
00026 #endif
00027 
00029 class LgiClass GDragDropSource
00030 #if defined WIN32
00031     : public IDropSource, public IEnumFORMATETC
00032 #elif defined XWIN
00033     : public QObject
00034 #endif
00035 {
00036     friend class GDataObject;
00037 
00038 protected:
00039     char *CurrentFormat;
00040     
00041     #if defined WIN32
00042     int Index;
00043 
00044     // IUnknown
00045     ULONG STDMETHODCALLTYPE AddRef();
00046     ULONG STDMETHODCALLTYPE Release();
00047     HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppv);
00048 
00049     // IEnumFORMATETC
00050     HRESULT STDMETHODCALLTYPE Next(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched);
00051     HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
00052     HRESULT STDMETHODCALLTYPE Reset();
00053     HRESULT STDMETHODCALLTYPE Clone(IEnumFORMATETC **ppenum);
00054 
00055     // IDropSource
00056     HRESULT STDMETHODCALLTYPE QueryContinueDrag(BOOL fEscapePressed, DWORD InputState);
00057     HRESULT STDMETHODCALLTYPE GiveFeedback(DWORD dwEffect);
00058     #endif
00059 
00061     bool CreateFileDrop(GVariant *Var, GMouse &m, List<char> &Files);
00062 
00063     #ifdef XWIN
00064     void OnSelectionRequest(Display *Dsp, XEvent &Event, QWidget *W, Atom XdndSelection); 
00065     #endif
00066     
00067 public:
00068     GDragDropSource();
00069     ~GDragDropSource();
00070 
00072     int Drag(GView *SourceWnd, int Effect);
00073 
00075     virtual void OnRegister(bool Success) {}
00077     virtual void OnStartData() {}
00079     virtual void OnEndData() {}
00080     
00084     virtual bool GetData(GVariant *Data,        // out
00085                          char *Format           // in
00086                          ) { return false; }
00087 
00104     virtual bool GetFormats(List<char> &Formats) { return false; }
00105 };
00106 
00107 class LgiClass GDragDropTarget
00108 #if defined WIN32
00109     : public IDropTarget
00110 #elif defined XWIN
00111     : public QObject
00112 #endif
00113 {
00114 private:
00115     GView *To;
00116     uchar *DragDropData;
00117     int DragDropLength;
00118     List<char> Formats;
00119 
00120     #if defined WIN32
00121     // IUnknown
00122     ULONG STDMETHODCALLTYPE AddRef();
00123     ULONG STDMETHODCALLTYPE Release();
00124     HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppv);
00125 
00126     // IDropTarget
00127     HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
00128     HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
00129     HRESULT STDMETHODCALLTYPE DragLeave(void);
00130     HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
00131 
00132     #endif
00133 
00134 protected:
00135     #if defined WIN32
00136     // Data elements
00137     IDataObject *DataObject;
00138 
00139     // Tools
00140     bool OnDropFileGroupDescriptor(FILEGROUPDESCRIPTOR *Data, GArray<char*> &Files);
00141     #endif
00142 
00143 public:
00144     GDragDropTarget();
00145     ~GDragDropTarget();
00146 
00147     // call this when you have a HWND
00148     void SetWindow(GView *To);
00149 
00150     // Override these
00151 
00152     // Events
00153     virtual void OnDragInit(bool Success) {}
00154     virtual void OnDragEnter() {}
00155     virtual void OnDragExit() {}
00156 
00157     // 'WillAccept' is called to see whether this target
00158     // can cope with any of the data types being passed to it.
00159     // Once you have decided what format you want the data in
00160     // clear all the other formats from the list. The first
00161     // format left in the list will be passed to the 'OnDrop'
00162     // function.
00163     virtual int WillAccept(List<char> &Formats, GdcPt2 Pt, int KeyState) { return DROPEFFECT_NONE; }
00164 
00165     // 'OnDrop' is called when the user releases the data over
00166     // your window. The data is going to be a binary GVariant
00167     // in the format you accepted earlier.
00168     virtual int OnDrop(char *Format, GVariant *Data, GdcPt2 Pt, int KeyState) { return DROPEFFECT_NONE; }
00169 };
00170 
00171 #endif

Generated on Tue May 2 10:24:41 2006 for Lgi by  doxygen 1.4.1