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
Shinya Kitaoka 120a6e
class DVAPI TOutOfMemory {};
Shinya Kitaoka 120a6e
class DVAPI TInitFailed {};
Shinya Kitaoka 120a6e
class DVAPI TDragDropExpt {};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Shinya Kitaoka 120a6e
// TDropSource/////
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TDropSource {
Toshihiro Shimizu 890ddd
#if defined(__GNUC__)
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  class Imp;
Toshihiro Shimizu 890ddd
#if defined(__GNUC__)
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  Imp *m_imp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TDropSource(const TDropSource &);
Shinya Kitaoka 120a6e
  TDropSource &operator=(const TDropSource &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum DropEffect {
Shinya Kitaoka 120a6e
    None = 0,
Shinya Kitaoka 120a6e
    Copy,
Shinya Kitaoka 120a6e
    Move,
Shinya Kitaoka 120a6e
    Link,
Shinya Kitaoka 120a6e
    CopyScroll,
Shinya Kitaoka 120a6e
    MoveScroll,
Shinya Kitaoka 120a6e
    LinkScroll
Shinya Kitaoka 120a6e
  };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDropSource();
Shinya Kitaoka 120a6e
  virtual ~TDropSource();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isValid() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DropEffect doDragDrop(const TDataObject &data);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // viene chiamata durante il drag su un target passando come
Shinya Kitaoka 120a6e
  // argomento il valore ritornato dalla onOver() del target
Shinya Kitaoka 120a6e
  // virtual CursorToUse setCursor(DropEffect dropEffect);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void setCursor(DropEffect dropEffect);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Shinya Kitaoka 120a6e
// TDropTarget/////
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
//! \brief Ascoltatore degli eventi per il Drag&Drop
Shinya Kitaoka 120a6e
class DVAPI TDragDropListener {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class Event {
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    const TData *const m_data;
Shinya Kitaoka 120a6e
    TPoint m_pos;
Shinya Kitaoka 120a6e
    unsigned int m_buttonMask;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    Event(TData *data) : m_data(data), m_buttonMask(0){};
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDragDropListener(){};
Shinya Kitaoka 120a6e
  virtual ~TDragDropListener(){};
Shinya Kitaoka 120a6e
  //! Funzione per il drop di un file - ingresso nel pannello
Shinya Kitaoka 120a6e
  virtual TDropSource::DropEffect onEnter(const Event &event) = 0;
Shinya Kitaoka 120a6e
  //! Funzione per il drop di un file - interno al pannello
Shinya Kitaoka 120a6e
  virtual TDropSource::DropEffect onOver(const Event &event) = 0;
Shinya Kitaoka 120a6e
  //! Funzione per il drop di un file - rilascio del file
Shinya Kitaoka 120a6e
  virtual TDropSource::DropEffect onDrop(const Event &event) = 0;
Shinya Kitaoka 120a6e
  //! Funzione per il drop di un file - uscita dal pannello
Shinya Kitaoka 120a6e
  virtual void onLeave() = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////
Shinya Kitaoka 120a6e
// TDataObject/////
Toshihiro Shimizu 890ddd
//////////////////
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TDataObject {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class Imp;
Shinya Kitaoka 120a6e
  Imp *m_imp;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TDataObject(const TDataObject &);
Shinya Kitaoka 120a6e
  TDataObject &operator=(const TDataObject &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  enum DataType { Text, File, Bitmap };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TDataObject();
Shinya Kitaoka 120a6e
  ~TDataObject();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Costruttore per Text
Shinya Kitaoka 120a6e
  TDataObject(const std::string &str);
Shinya Kitaoka 120a6e
  TDataObject(const std::wstring &str);
Shinya Kitaoka 120a6e
  // Costruttore per File
Shinya Kitaoka 120a6e
  TDataObject(const std::vector<std::string> &vStr);</std::string>
Shinya Kitaoka 120a6e
  TDataObject(const std::vector<std::wstring> &vStr);</std::wstring>
Shinya Kitaoka 120a6e
  // Costruttore per dt_bitmap o eventualmente un tipo proprietario
Shinya Kitaoka 120a6e
  TDataObject(DataType dataType, const unsigned char *data,
Shinya Kitaoka 120a6e
              const unsigned int dataLen);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool getDataTypes(std::vector<datatype> &dataType) const;</datatype>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool getData(string &str) const;
Shinya Kitaoka 120a6e
  bool getData(std::vector<string> &vStr) const;</string>
Shinya Kitaoka 120a6e
  bool getData(DataType dataType, unsigned char *&data,
Shinya Kitaoka 120a6e
               unsigned int *dataLen) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // friend class TDropSource::Imp;
Shinya Kitaoka 120a6e
  // friend class TDropTarget::Imp;
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
class DVAPI TDNDGenericDataHolder {
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  TDNDGenericDataHolder() {}
Shinya Kitaoka 120a6e
  static TDNDGenericDataHolder *m_holder;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual ~TDNDGenericDataHolder() {}
Shinya Kitaoka 120a6e
  static bool isDraggingCustomData() { return m_holder != 0; }
Shinya Kitaoka 120a6e
  TDropSource::DropEffect doDragDrop();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Shinya Kitaoka 120a6e
class TDNDDataHolder : public TDNDGenericDataHolder {
Shinya Kitaoka 120a6e
  T *m_value;
Shinya Kitaoka 120a6e
  string m_name;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TDNDDataHolder(T *value, string name = "") : m_value(value), m_name(name) {
Shinya Kitaoka 120a6e
    m_holder = this;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ~TDNDDataHolder() { m_holder = 0; }
Shinya Kitaoka 120a6e
  T *getValue() const { return m_value; }
Shinya Kitaoka 120a6e
  string getName() const { return m_name; }
Shinya Kitaoka 120a6e
  static T *getCurrentValue() {
Shinya Kitaoka 120a6e
    TDNDDataHolder<t> *holder = dynamic_cast<tdnddataholder<t> *>(m_holder);</tdnddataholder<t></t>
Shinya Kitaoka 120a6e
    return holder ? holder->getValue() : 0;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif