dragitemi.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _DRAGITEMI_H
  2. #define _DRAGITEMI_H
  3. #include "dragitem.h"
  4. #include <bfc/common.h>
  5. #include <bfc/string/stringW.h>
  6. #include <bfc/ptrlist.h>
  7. class DragItemI : public DragItem
  8. {
  9. public:
  10. DragItemI(const wchar_t *datatype, void *datum = NULL);
  11. virtual ~DragItemI() {}
  12. void addVoidDatum(void *newdatum); // up to you to cast it right
  13. const wchar_t *getDatatype();
  14. int getNumData();
  15. void *getDatum(int pos = 0);
  16. private:
  17. RECVS_DISPATCH;
  18. StringW datatype;
  19. PtrList<char> datalist;
  20. };
  21. template <class T>
  22. class DragItemT : public DragItemI
  23. {
  24. public:
  25. DragItemT(T *item = NULL) : DragItemI(T::dragitem_getDatatype(), item) {}
  26. static inline DragItemI *create(T *item) { return new DragItemT<T>(item); }
  27. void addDatum(T *newdatum)
  28. {
  29. addVoidDatum(static_cast<void *>(newdatum));
  30. }
  31. };
  32. template <class T>
  33. class DragItemCast
  34. {
  35. public:
  36. DragItemCast(DragItem *_item, int _pos = 0) : item(_item), pos(_pos) {}
  37. operator T *()
  38. {
  39. if (item == NULL || !STREQL(T::dragitem_getDatatype(), item->getDatatype()))
  40. return NULL;
  41. else
  42. return static_cast<T*>(item->getDatum(pos));
  43. }
  44. private:
  45. DragItem *item;
  46. int pos;
  47. };
  48. #endif