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 
00027 LgiFunc int FormatToInt(char *s);
00029 LgiFunc char *FormatToStr(int f);
00030 
00031 #elif defined LINUX
00032 
00034 #define FormatToInt(c)      XInternAtom(XDisplay(), c, false)
00035 
00036 #define FormatToStr(f)      XGetAtomName(XDisplay(), f)
00037 
00038 #if !defined(XWIN) && !defined(YWIN)
00039     #error Either XWIN or YWIN must be defined.
00040 #endif
00041 
00042 #endif
00043 
00045 class LgiClass GDragDropSource
00046 #if defined WIN32
00047     : public IDropSource, public IEnumFORMATETC
00048 #elif defined XWIN
00049     : public QObject
00050 #endif
00051 {
00052     friend class GDataObject;
00053 
00054 protected:
00055     char *CurrentFormat;
00056     
00057     #if defined WIN32
00058     int Index;
00059 
00060     // IUnknown
00061     ULONG STDMETHODCALLTYPE AddRef();
00062     ULONG STDMETHODCALLTYPE Release();
00063     HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppv);
00064 
00065     // IEnumFORMATETC
00066     HRESULT STDMETHODCALLTYPE Next(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched);
00067     HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
00068     HRESULT STDMETHODCALLTYPE Reset();
00069     HRESULT STDMETHODCALLTYPE Clone(IEnumFORMATETC **ppenum);
00070 
00071     // IDropSource
00072     HRESULT STDMETHODCALLTYPE QueryContinueDrag(BOOL fEscapePressed, DWORD InputState);
00073     HRESULT STDMETHODCALLTYPE GiveFeedback(DWORD dwEffect);
00074     #endif
00075 
00077     bool CreateFileDrop(GVariant *Var, GMouse &m, List<char> &Files);
00078 
00079     #ifdef XWIN
00080     void OnSelectionRequest(Display *Dsp, XEvent &Event, QWidget *W, Atom XdndSelection); 
00081     #endif
00082     
00083 public:
00084     GDragDropSource();
00085     ~GDragDropSource();
00086 
00088     int Drag(GView *SourceWnd, int Effect);
00089 
00091     virtual void OnRegister(bool Success) {}
00093     virtual void OnStartData() {}
00095     virtual void OnEndData() {}
00096     
00100     virtual bool GetData(GVariant *Data,        // out
00101                          char *Format           // in
00102                          ) { return false; }
00103 
00120     virtual bool GetFormats(List<char> &Formats) { return false; }
00121 };
00122 
00123 class LgiClass GDragDropTarget
00124 #if defined WIN32
00125     : public IDropTarget
00126 #elif defined XWIN
00127     : public QObject
00128 #endif
00129 {
00130 private:
00131     GView *To;
00132     uchar *DragDropData;
00133     int DragDropLength;
00134     List<char> Formats;
00135 
00136     #if defined WIN32
00137     // IUnknown
00138     ULONG STDMETHODCALLTYPE AddRef();
00139     ULONG STDMETHODCALLTYPE Release();
00140     HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppv);
00141 
00142     // IDropTarget
00143     HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
00144     HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
00145     HRESULT STDMETHODCALLTYPE DragLeave(void);
00146     HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect);
00147 
00148     #endif
00149 
00150 protected:
00151     #if defined WIN32
00152     // Data elements
00153     IDataObject *DataObject;
00154 
00155     // Tools
00156     bool OnDropFileGroupDescriptor(FILEGROUPDESCRIPTOR *Data, List<char> &Files);
00157     #endif
00158 
00159 public:
00160     GDragDropTarget();
00161     ~GDragDropTarget();
00162 
00163     // call this when you have a HWND
00164     void SetWindow(GView *To);
00165 
00166     // Override these
00167 
00168     // Events
00169     virtual void OnDragInit(bool Success) {}
00170     virtual void OnDragEnter() {}
00171     virtual void OnDragExit() {}
00172 
00173     // 'WillAccept' is called to see whether this target
00174     // can cope with any of the data types being passed to it.
00175     // Once you have decided what format you want the data in
00176     // clear all the other formats from the list. The first
00177     // format left in the list will be passed to the 'OnDrop'
00178     // function.
00179     virtual int WillAccept(List<char> &Formats, GdcPt2 Pt, int KeyState) { return DROPEFFECT_NONE; }
00180 
00181     // 'OnDrop' is called when the user releases the data over
00182     // your window. The data is going to be a binary GVariant
00183     // in the format you accepted earlier.
00184     virtual int OnDrop(char *Format, GVariant *Data, GdcPt2 Pt, int KeyState) { return DROPEFFECT_NONE; }
00185 };
00186 
00187 #endif

Generated on Wed Oct 26 14:46:48 2005 for Lgi by  doxygen 1.4.1