svc_droptarget.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef _SVC_DROPTARGET_H
  2. #define _SVC_DROPTARGET_H
  3. #include <bfc/dispatch.h>
  4. #include <api/service/services.h>
  5. class DragInterface; // see bfc/drag.h
  6. class NOVTABLE svc_dropTarget : public Dispatchable
  7. {
  8. public:
  9. static FOURCC getServiceType() { return WaSvc::DROPTARGET; }
  10. int testTarget(FOURCC type);
  11. DragInterface *getDragInterfaceForType(FOURCC type);
  12. int releaseDragInterface(DragInterface *di);
  13. protected:
  14. enum {
  15. TESTTARGET=100,
  16. GETDRAGINTERFACEFORTYPE=200,
  17. RELEASEDRAGINTERFACE=210,
  18. };
  19. };
  20. inline
  21. int svc_dropTarget::testTarget(FOURCC type) {
  22. return _call(TESTTARGET, 0, type);
  23. }
  24. inline
  25. DragInterface *svc_dropTarget::getDragInterfaceForType(FOURCC type) {
  26. return _call(GETDRAGINTERFACEFORTYPE, (DragInterface*)NULL, type);
  27. }
  28. inline
  29. int svc_dropTarget::releaseDragInterface(DragInterface *di) {
  30. return _call(RELEASEDRAGINTERFACE, 0, di);
  31. }
  32. class svc_dropTargetI : public svc_dropTarget {
  33. public:
  34. virtual int testTarget(FOURCC type)=0;
  35. virtual DragInterface *getDragInterfaceForType(FOURCC type)=0;
  36. virtual int releaseDragInterface(DragInterface *di)=0;
  37. protected:
  38. RECVS_DISPATCH;
  39. };
  40. #include <api/service/servicei.h>
  41. template <class T>
  42. class DropTargetCreator : public waServiceFactoryTSingle<svc_dropTarget, T> { };
  43. #include <api/service/svc_enum.h>
  44. #include <api/wnd/drag.h>
  45. class DropTargetEnum : public SvcEnumT<svc_dropTarget> {
  46. public:
  47. DropTargetEnum(FOURCC type) : dt_type(type) {}
  48. static int throwDrop(FOURCC type, ifc_window *sourceWnd, int x=0, int y=0) {
  49. DropTargetEnum dte(type);
  50. svc_dropTarget *sdt = dte.getFirst();
  51. if (sdt == NULL) return 0;
  52. DragInterface *di = sdt->getDragInterfaceForType(type);
  53. int r = 0;
  54. if (di != NULL) r = di->dragDrop(sourceWnd, 0, 0);
  55. sdt->releaseDragInterface(di);
  56. return r;
  57. }
  58. protected:
  59. virtual int testService(svc_dropTarget *svc) {
  60. return (svc->testTarget(dt_type));
  61. }
  62. private:
  63. FOURCC dt_type;
  64. };
  65. #endif