idraganddrop.h

Go to the documentation of this file.
00001 /* 
00002  *    iDragAndDrop.h - SDK API to desktop drag-and-drop services in MAX
00003  *
00004  *       Copyright (c) Autodesk, Inc, 2000.  John Wainwright.
00005  *
00006  */
00007 
00008 #pragma once
00009 
00010 #include "maxheap.h"
00011 #include "iFnPub.h"
00012 #include "iMacroScript.h"
00013 #include "GetCOREInterface.h"
00014 
00015 // forward declarations
00016 class IDragAndDropMgr; 
00017 class DragAndDropHandler;
00018 class DropType;
00019 
00020 // Core interface to the OLE drag-and-drop manager
00021 
00022 // utility Tab<> specialization to hold URL strings
00036 class URLTab : public Tab<MCHAR*>
00037 {
00038 public:
00039    BOOL downloaded;  // set to indicate URL module has been downloaded & names now reflect local copies
00040 
00044    URLTab()  { downloaded = FALSE; }
00050    ~URLTab() { Clear(); }
00052    CoreExport URLTab& operator=(const Tab<MCHAR*>& tb);
00054    CoreExport URLTab& operator=(const URLTab& tb);
00060    CoreExport void Add(MCHAR* url);
00069    CoreExport void Change(int i, MCHAR* url);
00072    CoreExport void Clear();
00073 };
00074 
00075 // drag and drop Manager interface ID
00076 #define DND_MGR_INTERFACE   Interface_ID(0x51163ddb, 0x2a4f1619)
00077 
00080 inline IDragAndDropMgr* GetDragAndDropMgr() { return (IDragAndDropMgr*)GetCOREInterface(DND_MGR_INTERFACE); }
00081 
00082 
00084 enum
00085 {
00086     dndmgr_enableDandD, 
00087     dndmgr_globalEnableDnD, 
00088     dndmgr_isEnabled, 
00089     dndmgr_dropPackage, 
00090     dndmgr_downloadDirectory, 
00091     dndmgr_downloadPackage,
00092     dndmgr_downloadUrlToDisk,
00093     dndmgr_importContextNode,
00094 }; 
00095 
00140 class IDragAndDropMgr : public FPStaticInterface 
00141 {
00142 public:
00145     virtual void    EnableDandD(BOOL flag)=0;
00146 
00149     virtual BOOL   IsEnabled()=0;
00150 
00152 
00161     virtual BOOL   EnableDandD(HWND hwnd, BOOL flag, DragAndDropHandler* handler = NULL)=0;
00162 
00179     virtual BOOL   DropPackage(HWND hwnd, POINT& point, URLTab& module)=0; 
00180     
00189     virtual BOOL   DownloadPackage(URLTab& module, MCHAR* directory, HWND hwnd = NULL, bool showProgress = false)=0; 
00190 
00193     virtual MCHAR* GetDownloadDirectory()=0;
00194     
00197     virtual int    NumHandlers(HWND hwnd)=0;        // iterate handlers for given window
00198     
00202     virtual DragAndDropHandler* GetHandler(HWND hwnd, int i)=0;
00203 
00213     virtual bool   DownloadUrlToDisk(HWND hwnd, MCHAR* url, MCHAR* fileName, DWORD dlgflags=0)=0;
00214 
00216     virtual INode* ImportContextNode()=0;
00217 }; 
00218 
00219 #pragma warning(push)
00220 #pragma warning(disable:4100)
00221 
00224 /*  Instances of these classes can be registered with the drag and drop manager 
00225     when enabling a window for drag and drop activity. Virtual methods on these
00226     instances called to handle the various drag and drop events. Use 
00227     \code 
00228     IDragAndDropMgr::EnableDnD(hwnd, flag, &myHandler)
00229     \endcode 
00230     to enable drag and drop in a window and specify the DragAndDropHandler instance
00231     that will handle drag and drop events for that window. Note that one 
00232     DragAndDropHandler instance can potentially be shared among many HWND windows. 
00233     Further, a parent window can be enabled for drag and drop and this effectively
00234     causes all child windows to be enabled and handled by the given handler (unless 
00235     overriden by an explicit <b>EnableDnD</b> with a different handler on a child).\n\n
00236     
00237     There are actually two sets of drag and drop event handler virtual methods in the base
00238     class, a low-level set that equates to the methods on the OLE IDropTarget
00239     interface that take raw IDataObject drop data and a high-level set that take
00240     fully-parsed DropType drop data. The low-level methods have default implementations
00241     provided that do this parsing and call the corresponding high-level method, 
00242     so in most cases you only need to provide implementations for the high-level methods. 
00243     You would provide implementations of the low-level methods if custom parsing of the 
00244     IDataObject is required.
00245     \sa  Class IDragAndDropMgr, Class DropType
00246 */
00247 class DragAndDropHandler : public InterfaceServer
00248 {
00249 public:
00251     DragAndDropHandler() 
00252         : current_droptype(NULL)
00253     {
00254         if (dndMgr == NULL)
00255             dndMgr = GetDragAndDropMgr();
00256     }
00257 
00316     CoreExport virtual HRESULT DragEnter(HWND window, IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
00317 
00342     CoreExport virtual HRESULT Drop(HWND window, IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect);
00366     CoreExport virtual HRESULT DragOver(HWND window, DWORD grfKeyState, POINTL pt, DWORD * pdwEffect);
00379     CoreExport virtual HRESULT DragLeave(HWND window) { return E_FAIL; }
00380 
00381     // high-level drag-and-drop operations, the dataObject has been decoded and the drop-type parsed
00415     virtual HRESULT DragEnter(HWND window, DropType* type, DWORD grfKeyState, POINT& pt, DWORD* pdwEffect) { return E_FAIL; }
00487     virtual HRESULT Drop(HWND window, DropType* type, DWORD grfKeyState, POINT& pt, DWORD* pdwEffect) { return E_FAIL; }
00514     virtual HRESULT DragOver(HWND window, DWORD grfKeyState, POINT& pt, DWORD * pdwEffect) { return E_FAIL; }
00515 
00523     virtual void Acquire() { }; 
00526 
00532     virtual void Release() { }; 
00533 
00534 protected:
00537     DropType*  current_droptype;
00539     CoreExport static IDragAndDropMgr* dndMgr; 
00540 };
00541 
00542 // class DropClipFormat
00543 // base class for the various supported clipboard formats.
00544 // Distinguished instance of each subclass represents a
00545 // particular IDataObject clip format or module of related formats
00546 // that can be accepted by MAX's various windows.  Prime responsibility
00547 // of each is to recognize its presence in a dropped (pasted?) IDataObject
00548 // and to parse the data object into one of the acceptable DropTypes.
00549 // 
00565 class DropClipFormat : public InterfaceServer
00566 {
00567 protected:
00568    CoreExport static Tab<DropClipFormat*> clipFmts;  // table of supported clip formats
00569 public:
00570    // each DropClimFormat instance created is kept in the clipFmts table
00574    DropClipFormat() { DropClipFormat* cf = this; clipFmts.Append(1, &cf); }
00575 
00576    // used primarily by the DragEnter() handler to find the DropClipFormat
00577    // corresponding to the currently dropping IDataObject
00586    CoreExport static DropClipFormat* FindClipFormat(IDataObject* pDataObject);
00587 
00588    // specialized by individual clipformats to detect its format(s) present in 
00589    // the given IDataObject
00599    virtual bool CheckClipFormat(IDataObject* pDataObject) { return false; }
00600    
00601    // specialized by individual clip format types to parse IDataObject
00602    // into appropriate DropType
00680    virtual DropType* ParseDataObject(IDataObject* pDataObject) { return NULL; }
00681 };
00682 
00683 // built-in clip formats
00684 
00685 // iDrop module URL
00690 class IDropPackageClipFmt : public DropClipFormat
00691 {
00692 public:
00693    bool CheckClipFormat(IDataObject* pDataObject);
00694    DropType* ParseDataObject(IDataObject* pDataObject);
00695 };
00696 
00697 // VIZable file URL
00702 class VIZableClipFmt : public DropClipFormat
00703 {
00704 public:
00705    bool CheckClipFormat(IDataObject* pDataObject);
00706    DropType* ParseDataObject(IDataObject* pDataObject);
00707 };
00708 
00709 // internal dropScript
00714 class DropScriptClipFmt : public DropClipFormat
00715 {
00716 public:
00717    bool CheckClipFormat(IDataObject* pDataObject);
00718    DropType* ParseDataObject(IDataObject* pDataObject);
00719 };
00720 
00721 
00722 // class DropType
00723 // base class for dropable content types
00724 // Distinguished instances of subclasses represent different types of drop content, 
00725 // such as a file distinguished by file suffix or a scene object
00726 // The active DropClipFormat parses dropped IDataObject into one
00727 // of these dropped types, filling its data members with appropriate
00728 // guff from the data object.
00762 class DropType : public MaxHeapOperators, public IDropSource, public IDataObject
00763 {
00764 protected:
00765    CoreExport static IDragAndDropMgr* dndMgr;   // cached pointer to drag and drop manager
00766    CoreExport static bool dragging;       // drop source state...
00767    CoreExport static POINT startPt;
00768    CoreExport static WPARAM startKeyState;
00769    CoreExport static HWND startWnd;
00770    CoreExport static bool loaded;            // flags if curent module already downloaded
00771 
00772 public:
00773    // currently dropping data object
00774    CoreExport static IDataObject* current_dataobject;
00775 
00777    DropType() { if (dndMgr == NULL) dndMgr = GetDragAndDropMgr(); }
00779      CoreExport virtual ~DropType();
00780    
00781    // clears current parsed drop data
00785    static void Init() { current_dataobject = NULL; loaded = false; }
00786 
00787    // DropType code access, provides an integer code specific
00788    // to the droptype
00790    virtual int TypeCode()=0;
00805    virtual bool IsDropType(int code) { return code == TypeCode(); }
00806    
00807    // ------- drop target methods & members --------------
00808 
00809    // perform any droptype-specific load prior to using the data, eg 
00810    // downloading URLs to local machine
00821    virtual bool Load(bool showProgress = true) { return true; }
00822 
00823    // dropeffect currently supported by accepted dropping type
00828    virtual DWORD DropEffect() { return DROPEFFECT_MOVE; }
00829 
00830    // -------- drop source methods and members -----------------
00831 
00832    // from IUnknown
00833    CoreExport STDMETHODIMP QueryInterface(REFIID iid, void** ppvObject);
00834    CoreExport STDMETHODIMP_(ULONG) AddRef(void)  { return 1; }
00835    CoreExport STDMETHODIMP_(ULONG) Release(void) { return 1; }
00836    
00837    // from IDataObject
00838    CoreExport STDMETHODIMP GetData(FORMATETC* pFormatetc, STGMEDIUM* pmedium) { return E_UNEXPECTED; }
00839    CoreExport STDMETHODIMP GetDataHere(FORMATETC* pFormatetc, STGMEDIUM* pmedium) { return E_UNEXPECTED; }
00840    CoreExport STDMETHODIMP QueryGetData(FORMATETC* pFormatetc) { return E_UNEXPECTED; }
00841    CoreExport STDMETHODIMP GetCanonicalFormatEtc(FORMATETC* pFormatetcIn, FORMATETC* pFormatetcOut);
00842    CoreExport STDMETHODIMP SetData(FORMATETC* pFormatetc, STGMEDIUM* pmedium, BOOL fRelease);
00843    CoreExport STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC** ppenumFormatetc);
00844    CoreExport STDMETHODIMP DAdvise(FORMATETC* pFormatetc, DWORD advf, IAdviseSink* pAdvSink, DWORD* pdwConnection);
00845    CoreExport STDMETHODIMP DUnadvise(DWORD dwConnection);
00846    CoreExport STDMETHODIMP EnumDAdvise(IEnumSTATDATA** ppenumAdvise);
00847 
00848    // from IDropSource
00849    CoreExport STDMETHODIMP QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState);
00850    CoreExport STDMETHODIMP GiveFeedback(DWORD dwEffect) { return DRAGDROP_S_USEDEFAULTCURSORS; }
00851 
00852    // drop start checking methods 
00853    CoreExport virtual void InitDragDropCheck(LPARAM mousePt, WPARAM keyState, HWND hwnd);
00854    CoreExport virtual void CancelDragDropCheck();
00855    CoreExport virtual bool DragDropCheck(LPARAM mousePt, WPARAM keyState, DWORD allowedEffects);
00856    CoreExport virtual bool ReadyToDrag(){ return false; }
00857 };
00858 
00867 #define FILE_DROPTYPE            0x00000001     //!< A module of file names or URL's.
00868 #define DROPSCRIPT_DROPTYPE         0x00000002  //!< A dropScript.
00869 #define SCENEFILE_DROPTYPE       0x00000003     //!< The *.max scene file.
00870 #define IMAGEFILE_DROPTYPE       0x00000004     //!< The image files (.bmp, .tga, etc.).
00871 #define IMPORTFILE_DROPTYPE         0x00000005  //!< The importable files (.3ds, .dxf, etc.).
00872 #define SCRIPTFILE_DROPTYPE         0x00000006  //!< The script files (.ms, .mse, .mcr).
00873 #define DROPSCRIPTFILE_DROPTYPE     0x00000007  //!< The drop script files (.ds, .dse).
00874 #define BITMAP_DROPTYPE          0x00000008     //!< The bitmap type.
00875 #define MSZIPFILE_DROPTYPE       0x00000009     //!< The script zip module files (.mzp).
00876 #define PATHFILE_DROPTYPE        0x0000000a     //!< The path type.
00877 
00878 
00896 class FileDropType : public DropType
00897 {
00898 protected:
00899    CoreExport static Tab<FileDropType*> fileDropTypes;  // table of supported file drop types
00900     CoreExport static MSTR download_directory;            // cache for default download directory
00901 
00902    // URL download utilities
00903    CoreExport static bool CheckForCachedFile(MCHAR* filename);
00904    CoreExport static bool IsInternetCachedFile(const MCHAR* filename);
00905    CoreExport static bool  AppendUrlFilename(const MCHAR* szUrl, MCHAR* szPathname, bool& is_URL);
00906 
00907 public:
00908    CoreExport static URLTab current_package;
00909 
00911    FileDropType() { FileDropType* dt = this; fileDropTypes.Append(1, &dt); }
00915    static void Init() { current_package.Clear(); DropType::Init(); }
00916 
00917    // From DropType
00921    int TypeCode() { return FILE_DROPTYPE; }
00929    bool IsDropType(int code) { return code == TypeCode() || code == FILE_DROPTYPE; }
00930 
00931    // ------- drop target methods & members --------------
00932 
00938    CoreExport bool Load(bool showProgress = true);
00939    
00940    // global finder of assoicated droptype given filename (or pDataObject)
00951    CoreExport static FileDropType* FindDropType(MCHAR* filename, IDataObject* pDataObject = NULL);
00952 
00953    // specialize this for each droppable file type to provide type detector
00962    virtual bool     CheckDropType(MCHAR* filename) { return false; } 
00963 
00964    // module download utilities
00980    CoreExport static bool   DownloadPackage(URLTab& module, MCHAR* szDirectory, HWND hwnd = NULL, bool showProgress = true);
00983    CoreExport static MCHAR* GetDownloadDirectory();
00999    CoreExport static bool DownloadUrlToDisk(HWND hwnd, MCHAR* szUrl, MCHAR* szPathname, DWORD flags=0);
01000 
01001    // -------- drop source methods and members -----------------
01002 
01003    // from IDataObject
01004    STDMETHODIMP GetData(FORMATETC* pFormatetc, STGMEDIUM* pmedium) { return E_UNEXPECTED; }
01005    STDMETHODIMP GetDataHere(FORMATETC* pFormatetc, STGMEDIUM* pmedium) { return E_UNEXPECTED; }
01006    STDMETHODIMP QueryGetData(FORMATETC* pFormatetc) { return E_UNEXPECTED; }
01007 
01008 };
01009 
01010 #pragma warning(pop)
01011 
01012 
01013 // class DropScriptDropType
01014 //   intermediate base class for drop content in the form of a 
01015 //   dropScript 
01085 class DropScriptDropType : public DropType
01086 {
01087 public:
01088    CoreExport static MacroEntry* current_dropscript;
01089 
01090    // From DropType
01094    int TypeCode() { return DROPSCRIPT_DROPTYPE; }
01102    bool IsDropType(int code) { return code == TypeCode() || code == DROPSCRIPT_DROPTYPE; }
01110    DWORD DropEffect() { return DROPEFFECT_MOVE; }
01111    
01112    // ------- drop target methods & members --------------
01113 
01114    // compile & run support methods
01127    CoreExport BOOL CompileDropScript(MCHAR* filename);
01135    CoreExport BOOL RunDropScriptDragEnter(FPParams* params);
01144    CoreExport BOOL RunDropScriptDragOver(FPParams* params);
01153    CoreExport BOOL RunDropScriptDrop(FPParams* params);
01154 
01155    // -------- drop source methods and members -----------------
01156 
01157    // from IDataObject
01158    CoreExport STDMETHODIMP GetData(FORMATETC* pFormatetc, STGMEDIUM* pmedium);
01159    CoreExport STDMETHODIMP GetDataHere(FORMATETC* pFormatetc, STGMEDIUM* pmedium);
01160    CoreExport STDMETHODIMP QueryGetData(FORMATETC* pFormatetc);
01161 
01162    // drop start checking methods 
01173    void InitDragDropCheck(MacroEntry* dropscript, LPARAM mousePt, WPARAM keyState, HWND hwnd)
01174    {
01175       DropType::InitDragDropCheck(mousePt, keyState, hwnd);
01176       current_dropscript = dropscript;
01177    }
01182    bool ReadyToDrag() { return current_dropscript != NULL; }
01183 };
01184 
01185 // the built-in type classes
01186 
01187 // first the file types, usually sourced by the iDrop active-X control on a 
01188 // web page or by draggin files from the Windows desktop/explorer...
01189 
01190 // .max scene file
01196 class SceneFileDropType : public FileDropType
01197 {
01198 public:
01199    // From DropType
01203    int TypeCode() { return SCENEFILE_DROPTYPE; }
01204    
01205    // From FileDropType
01212    CoreExport bool CheckDropType(MCHAR* filename);
01213 };
01214 
01215 // image files (.bmp, .tga, etc.)
01221 class ImageFileDropType : public FileDropType
01222 {
01223 public:
01224    // From DropType
01228    int TypeCode() { return IMAGEFILE_DROPTYPE; }
01229    
01230    // From FileDropType
01237    CoreExport bool CheckDropType(MCHAR* filename);
01238 };
01239 
01240 // importable files (.3ds, .dxf, etc.)
01246 class ImportFileDropType : public FileDropType
01247 {
01248 public:
01249    // From DropType
01253    int TypeCode() { return IMPORTFILE_DROPTYPE; }
01254    
01255    // From FileDropType
01262    CoreExport bool CheckDropType(MCHAR* filename);
01263 };
01264 
01265 // script files (.ms, .mse, .mcr)
01271 class ScriptFileDropType : public FileDropType
01272 {
01273 public:
01274    // From DropType
01278    int TypeCode() { return SCRIPTFILE_DROPTYPE; }
01279    
01280    // From FileDropType
01287    CoreExport bool CheckDropType(MCHAR* filename);
01288 };
01289 
01290 // drop script files (.ds, .dse)
01298 class DropScriptFileDropType : public FileDropType, public DropScriptDropType
01299 {
01300 public:
01301    // From DropType
01305    int TypeCode() { return DROPSCRIPTFILE_DROPTYPE; }
01310    bool Load(bool showProgress = true);
01311    
01312    // From FileDropType
01319    CoreExport bool CheckDropType(MCHAR* filename);
01320 };
01321 
01322 // script zip module files (.mzp)
01336 class MSZipPackageFileDropType : public FileDropType, public DropScriptDropType
01337 {
01338 public:
01339     MSTR extract_dir;
01340     MSTR drop_file; 
01341    DropType* drop_file_type;   // if drop_file is not a dropScript
01342 
01343    // From DropType
01347    int TypeCode() { return MSZIPFILE_DROPTYPE; }
01352    bool Load(bool showProgress = true);
01353    
01354    // From FileDropType
01361    CoreExport bool CheckDropType(MCHAR* filename);
01362 };
01363 
01364 // MAX-internal types
01365 
01366 // bitmap
01372 class BitmapDropType : public DropType
01373 {
01374 public:
01375    // From DropType
01379    int TypeCode() { return BITMAP_DROPTYPE; }
01380    
01381 };
01382 
01384 
01388 class PathConfigDropType : public FileDropType
01389 {
01390 public:
01392 
01393    int TypeCode() { return PATHFILE_DROPTYPE; }
01394 
01396 
01401    CoreExport bool CheckDropType(MCHAR* filename);
01402 };
01403 
01404 // built-in type instances
01405 extern CoreExport SceneFileDropType sceneFileDropType; 
01406 extern CoreExport ImageFileDropType imageFileDropType; 
01407 extern CoreExport ScriptFileDropType scriptFileDropType; 
01408 extern CoreExport DropScriptFileDropType dropScriptFileDropType; 
01409 extern CoreExport DropScriptDropType dropScriptDropType; 
01410 extern CoreExport BitmapDropType bitmapDropType; 
01411 extern CoreExport MSZipPackageFileDropType msZipPackageFileDropType; 
01412 extern CoreExport PathConfigDropType pathConfigDropType;
01413 
01414