Class DropClipFormat

3DS Max Plug-In SDK

Class DropClipFormat

See Also: Class DropType, Class VIZableClipFmt, Class DropScriptClipFmt, List of DropTypes

class DropClipFormat : public InterfaceServer

Description:

This class is available in release 4.0 and later only.

DropClipFormat is the base class for the various supported clipboard formats contained in a dropped IDataObject. Subclasses represent particular IDataObject clip format or package of related formats that can be accepted by various windows in 3ds max. The prime responsibility of each is to recognize its presence in a dropped IDataObject and to parse the data object into one of the supported DropTypes. Each subclass should have a singleton instance created. This is automatically registered with the DnD system for use in the clipform recognition routines.

Data Members:

protected:

static Tab<DropClipFormat*> clipFmts;

The table of supported clip formats.

Methods:

public:

Prototype:

DropClipFormat();

Remarks:

Constructor.

Each DropClimFormat instance created is kept in the clipFmts table

Prototype:

static DropClipFormat* FindClipFormat(IDataObject* pDataObject);

Remarks:

This method returns a pointer to the DropClipFormat (singleton) corresponding to the clip format in the given IDataObject, or NULL if the IDataObject contains no recognizable formats. This is primarily used by the low-level default DragEnter() function in DnD manager.

Parameters:

IDataObject* pDataObject

The data object you wish to return the clip format for.

Prototype:

virtual bool CheckClipFormat(IDataObject* pDataObject)

Remarks:

This method should be implemented by each subclass to detect the presence of its clipformat(s) in the given IDataObject. See ParseDataObject() below for a detailed example.

Parameters:

IDataObject* pDataObject

The data object.

Return Value:

TRUE if the data was queries successfully, otherwise FALSE.

Default Implementation:

{ return false; }

Prototype:

virtual DropType* ParseDataObject(IDataObject* pDataObject);

Remarks:

This method should be implemented by each subclass to parse its clipformat(s) in the given IDataObject into the corresponding DropType subclass instance. For example, the DropClipFormats that accept dropped files will typically return one of the FileDropType subclasses depending on the filename suffix. A list of built-in clipformats:

 

IDropPackageClipFmt  iDrop XML package

VIZableClipFmt   VIZable file URL

DropScriptClipFmt  internal dropScript

 

Here's an example (simplified) VIZableClipFmt implementation, which accepts a custom CF_MAXURL clip format containing the URL of a file. CheckClipFormat() returns true if it finds the CF_MAXURL clipboard format present in the given IDataObject. Because this is a dropping file, ParseDataObject() clears the current droptype data (the FileDropType::Init(), extracts the file name from the IDataObject and installs it into the FileDropType current_package variable. It then asks the FileDropType class to recognize the actual file type being dropped and return the corresponding FileDropType subclass instance (using FileDropType::FindDropType()).

 

bool VIZableClipFmt::CheckClipFormat(IDataObject* pDataObject)

{

 // accept CF_MAXURL clip formats

 FORMATETC fmt = { NULL, NULL, DVASPECT_CONTENT, -1, NULL };

 fmt.cfFormat = RegisterClipboardFormat(_T("CF_MAXURL"));

 fmt.tymed = TYMED_HGLOBAL;

 return SUCCEEDED(pDataObject->QueryGetData(&fmt)) == TRUE;

}

DropType* VIZableClipFmt::ParseDataObject(IDataObject* pDataObject)

{

 // parse a CF_MAXURL clipformat into one of the FileDropTypes &

 // fill in the FileDropType::current_packge URLTab

 HRESULT hr;

 FORMATETC fmt = { NULL, NULL, DVASPECT_CONTENT, -1, NULL };

 STGMEDIUM stg = { TYMED_NULL, NULL, NULL };

 

 fmt.tymed = TYMED_HGLOBAL;

 fmt.cfFormat = RegisterClipboardFormat(_T("CF_MAXURL"));

 

 // clear out the file drop current data

 FileDropType::Init();

 

 // look for CF_MAXURL formats

 hr = pDataObject->GetData(&fmt, &stg);

 if(SUCCEEDED(hr))

 {

  // found, get the max file name

TCHAR szUrl[MAX_PATH];

  ZeroMemory(szUrl, sizeof(szUrl));

  wcstombs(szUrl,

reinterpret_cast<wchar_t*>(GlobalLock(stg.hGlobal)),

MAX_PATH-1);

  GlobalUnlock(stg.hGlobal);

  ReleaseStgMedium(&stg);

  // add it to the current_package URLTab

  FileDropType::current_package.Add(szUrl);

 }

 

// if we have a non-NULL package, get the appropriate

// FileDropType (usually based on file extension), by asking the

// utility DropType finder in FileDropType

 if (FileDropType::current_package.Count() > 0)

return FileDropType::FindDropType(

FileDropType::current_package[0], pDataObject);

 else

  return NULL;

}

Parameters:

IDataObject* pDataObject

The data object.

Return Value:

A pointer to the drop-type.

Default Implementation:

{ return NULL; }