dnd.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/motif/dnd.h
  3. // Purpose: declaration of wxDropTarget, wxDropSource classes
  4. // Author: Julian Smart
  5. // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling, Julian Smart
  6. // Licence: wxWindows licence
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_DND_H_
  9. #define _WX_DND_H_
  10. #include "wx/defs.h"
  11. #if wxUSE_DRAG_AND_DROP
  12. #include "wx/object.h"
  13. #include "wx/string.h"
  14. #include "wx/dataobj.h"
  15. #include "wx/cursor.h"
  16. //-------------------------------------------------------------------------
  17. // classes
  18. //-------------------------------------------------------------------------
  19. class WXDLLIMPEXP_FWD_CORE wxWindow;
  20. class WXDLLIMPEXP_FWD_CORE wxDropTarget;
  21. class WXDLLIMPEXP_FWD_CORE wxTextDropTarget;
  22. class WXDLLIMPEXP_FWD_CORE wxFileDropTarget;
  23. class WXDLLIMPEXP_FWD_CORE wxPrivateDropTarget;
  24. class WXDLLIMPEXP_FWD_CORE wxDropSource;
  25. //-------------------------------------------------------------------------
  26. // wxDropTarget
  27. //-------------------------------------------------------------------------
  28. class WXDLLIMPEXP_CORE wxDropTarget: public wxObject
  29. {
  30. public:
  31. wxDropTarget();
  32. virtual ~wxDropTarget();
  33. virtual void OnEnter() { }
  34. virtual void OnLeave() { }
  35. virtual bool OnDrop( long x, long y, const void *data, size_t size ) = 0;
  36. // Override these to indicate what kind of data you support:
  37. virtual size_t GetFormatCount() const = 0;
  38. virtual wxDataFormat GetFormat(size_t n) const = 0;
  39. // implementation
  40. };
  41. //-------------------------------------------------------------------------
  42. // wxTextDropTarget
  43. //-------------------------------------------------------------------------
  44. class WXDLLIMPEXP_CORE wxTextDropTarget: public wxDropTarget
  45. {
  46. public:
  47. wxTextDropTarget() {}
  48. virtual bool OnDrop( long x, long y, const void *data, size_t size );
  49. virtual bool OnDropText( long x, long y, const char *psz );
  50. protected:
  51. virtual size_t GetFormatCount() const;
  52. virtual wxDataFormat GetFormat(size_t n) const;
  53. };
  54. //-------------------------------------------------------------------------
  55. // wxPrivateDropTarget
  56. //-------------------------------------------------------------------------
  57. class WXDLLIMPEXP_CORE wxPrivateDropTarget: public wxDropTarget
  58. {
  59. public:
  60. wxPrivateDropTarget();
  61. // you have to override OnDrop to get at the data
  62. // the string ID identifies the format of clipboard or DnD data. a word
  63. // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
  64. // to the clipboard - the latter with the Id "WXWORD_FORMAT".
  65. void SetId( const wxString& id )
  66. { m_id = id; }
  67. wxString GetId()
  68. { return m_id; }
  69. private:
  70. virtual size_t GetFormatCount() const;
  71. virtual wxDataFormat GetFormat(size_t n) const;
  72. wxString m_id;
  73. };
  74. // ----------------------------------------------------------------------------
  75. // A drop target which accepts files (dragged from File Manager or Explorer)
  76. // ----------------------------------------------------------------------------
  77. class WXDLLIMPEXP_CORE wxFileDropTarget: public wxDropTarget
  78. {
  79. public:
  80. wxFileDropTarget() {}
  81. virtual bool OnDrop( long x, long y, const void *data, size_t size );
  82. virtual bool OnDropFiles( long x, long y,
  83. size_t nFiles, const char * const aszFiles[] );
  84. protected:
  85. virtual size_t GetFormatCount() const;
  86. virtual wxDataFormat GetFormat(size_t n) const;
  87. };
  88. //-------------------------------------------------------------------------
  89. // wxDropSource
  90. //-------------------------------------------------------------------------
  91. enum wxDragResult
  92. {
  93. wxDragError, // error prevented the d&d operation from completing
  94. wxDragNone, // drag target didn't accept the data
  95. wxDragCopy, // the data was successfully copied
  96. wxDragMove, // the data was successfully moved
  97. wxDragCancel // the operation was cancelled by user (not an error)
  98. };
  99. class WXDLLIMPEXP_CORE wxDropSource: public wxObject
  100. {
  101. public:
  102. wxDropSource( wxWindow *win );
  103. wxDropSource( wxDataObject &data, wxWindow *win );
  104. virtual ~wxDropSource(void);
  105. void SetData( wxDataObject &data );
  106. wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
  107. virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return true; }
  108. // implementation
  109. #if 0
  110. void RegisterWindow(void);
  111. void UnregisterWindow(void);
  112. wxWindow *m_window;
  113. wxDragResult m_retValue;
  114. wxDataObject *m_data;
  115. wxCursor m_defaultCursor;
  116. wxCursor m_goaheadCursor;
  117. #endif
  118. };
  119. #endif
  120. // wxUSE_DRAG_AND_DROP
  121. #endif
  122. //_WX_DND_H_