Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TDRAGDROP_INCLUDED
Toshihiro Shimizu 890ddd
#define TDRAGDROP_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tw/tw.h"
Toshihiro Shimizu 890ddd
// #include "tdata.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TWIN_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TDataObject;
Toshihiro Shimizu 890ddd
class TData;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
// Exceptions
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TOutOfMemory
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
class DVAPI TInitFailed
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
class DVAPI TDragDropExpt
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
//TDropSource/////
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TDropSource
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if defined(__GNUC__)
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	class Imp;
Toshihiro Shimizu 890ddd
#if defined(__GNUC__)
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	Imp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	// not implemented
Toshihiro Shimizu 890ddd
	TDropSource(const TDropSource &);
Toshihiro Shimizu 890ddd
	TDropSource &operator=(const TDropSource &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum DropEffect {
Toshihiro Shimizu 890ddd
		None = 0,
Toshihiro Shimizu 890ddd
		Copy,
Toshihiro Shimizu 890ddd
		Move,
Toshihiro Shimizu 890ddd
		Link,
Toshihiro Shimizu 890ddd
		CopyScroll,
Toshihiro Shimizu 890ddd
		MoveScroll,
Toshihiro Shimizu 890ddd
		LinkScroll
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDropSource();
Toshihiro Shimizu 890ddd
	virtual ~TDropSource();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isValid() const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DropEffect doDragDrop(const TDataObject &data);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// viene chiamata durante il drag su un target passando come
Toshihiro Shimizu 890ddd
	// argomento il valore ritornato dalla onOver() del target
Toshihiro Shimizu 890ddd
	//virtual CursorToUse setCursor(DropEffect dropEffect);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void setCursor(DropEffect dropEffect);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
//TDropTarget/////
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
//! \brief Ascoltatore degli eventi per il Drag&Drop
Toshihiro Shimizu 890ddd
class DVAPI TDragDropListener
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Event
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
	public:
Toshihiro Shimizu 890ddd
		const TData *const m_data;
Toshihiro Shimizu 890ddd
		TPoint m_pos;
Toshihiro Shimizu 890ddd
		unsigned int m_buttonMask;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		Event(TData *data) : m_data(data), m_buttonMask(0){};
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDragDropListener(){};
Toshihiro Shimizu 890ddd
	virtual ~TDragDropListener(){};
Toshihiro Shimizu 890ddd
	//! Funzione per il drop di un file - ingresso nel pannello
Toshihiro Shimizu 890ddd
	virtual TDropSource::DropEffect onEnter(const Event &event) = 0;
Toshihiro Shimizu 890ddd
	//! Funzione per il drop di un file - interno al pannello
Toshihiro Shimizu 890ddd
	virtual TDropSource::DropEffect onOver(const Event &event) = 0;
Toshihiro Shimizu 890ddd
	//! Funzione per il drop di un file - rilascio del file
Toshihiro Shimizu 890ddd
	virtual TDropSource::DropEffect onDrop(const Event &event) = 0;
Toshihiro Shimizu 890ddd
	//! Funzione per il drop di un file - uscita dal pannello
Toshihiro Shimizu 890ddd
	virtual void onLeave() = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
//TDataObject/////
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TDataObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Imp;
Toshihiro Shimizu 890ddd
	Imp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// not implemented
Toshihiro Shimizu 890ddd
	TDataObject(const TDataObject &);
Toshihiro Shimizu 890ddd
	TDataObject &operator=(const TDataObject &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	enum DataType {
Toshihiro Shimizu 890ddd
		Text,
Toshihiro Shimizu 890ddd
		File,
Toshihiro Shimizu 890ddd
		Bitmap
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TDataObject();
Toshihiro Shimizu 890ddd
	~TDataObject();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Costruttore per Text
Toshihiro Shimizu 890ddd
	TDataObject(const std::string &str);
Toshihiro Shimizu 890ddd
	TDataObject(const std::wstring &str);
Toshihiro Shimizu 890ddd
	//Costruttore per File
Toshihiro Shimizu 890ddd
	TDataObject(const std::vector<std::string> &vStr);</std::string>
Toshihiro Shimizu 890ddd
	TDataObject(const std::vector<std::wstring> &vStr);</std::wstring>
Toshihiro Shimizu 890ddd
	//Costruttore per dt_bitmap o eventualmente un tipo proprietario
Toshihiro Shimizu 890ddd
	TDataObject(DataType dataType, const unsigned char *data, const unsigned int dataLen);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool getDataTypes(std::vector<datatype> &dataType) const;</datatype>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool getData(string &str) const;
Toshihiro Shimizu 890ddd
	bool getData(std::vector<string> &vStr) const;</string>
Toshihiro Shimizu 890ddd
	bool getData(DataType dataType, unsigned char *&data, unsigned int *dataLen) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//friend class TDropSource::Imp;
Toshihiro Shimizu 890ddd
	//friend class TDropTarget::Imp;
Toshihiro Shimizu 890ddd
	friend class TEnumFormatEtc;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// void DVAPI uffa(TWidget *w);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// Gestione (discutibilissima) del drag&drop "interno" con tipi speciali
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// nel dropSource:
Toshihiro Shimizu 890ddd
//   MyType *data = ...
Toshihiro Shimizu 890ddd
//   TDNDDataHolder<mytype> holder(data);</mytype>
Toshihiro Shimizu 890ddd
//   holder.doDragDrop();
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// nel target
Toshihiro Shimizu 890ddd
//   if(MyType *data = TDNDDataHolder<mytype>::getCurrentValue())</mytype>
Toshihiro Shimizu 890ddd
//     {
Toshihiro Shimizu 890ddd
//     }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TDNDGenericDataHolder
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TDNDGenericDataHolder() {}
Toshihiro Shimizu 890ddd
	static TDNDGenericDataHolder *m_holder;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual ~TDNDGenericDataHolder() {}
Toshihiro Shimizu 890ddd
	static bool isDraggingCustomData() { return m_holder != 0; }
Toshihiro Shimizu 890ddd
	TDropSource::DropEffect doDragDrop();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TDNDDataHolder : public TDNDGenericDataHolder
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	T *m_value;
Toshihiro Shimizu 890ddd
	string m_name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TDNDDataHolder(T *value, string name = "") : m_value(value), m_name(name) { m_holder = this; }
Toshihiro Shimizu 890ddd
	~TDNDDataHolder() { m_holder = 0; }
Toshihiro Shimizu 890ddd
	T *getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
	string getName() const { return m_name; }
Toshihiro Shimizu 890ddd
	static T *getCurrentValue()
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		TDNDDataHolder<t> *holder = dynamic_cast<tdnddataholder<t> *>(m_holder);</tdnddataholder<t></t>
Toshihiro Shimizu 890ddd
		return holder ? holder->getValue() : 0;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif