dnd.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk1/dnd.h
  3. // Purpose: declaration of the wxDropTarget class
  4. // Author: Robert Roebling
  5. // Copyright: (c) 1998 Vadim Zeitlin, Robert Roebling
  6. // Licence: wxWindows licence
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef __GTKDNDH__
  9. #define __GTKDNDH__
  10. #if wxUSE_DRAG_AND_DROP
  11. #include "wx/object.h"
  12. #include "wx/string.h"
  13. #include "wx/dataobj.h"
  14. #include "wx/cursor.h"
  15. #include "wx/icon.h"
  16. #include "wx/gdicmn.h"
  17. //-------------------------------------------------------------------------
  18. // classes
  19. //-------------------------------------------------------------------------
  20. class WXDLLIMPEXP_FWD_CORE wxWindow;
  21. class WXDLLIMPEXP_FWD_CORE wxDropTarget;
  22. class WXDLLIMPEXP_FWD_CORE wxTextDropTarget;
  23. class WXDLLIMPEXP_FWD_CORE wxFileDropTarget;
  24. class WXDLLIMPEXP_FWD_CORE wxDropSource;
  25. // ----------------------------------------------------------------------------
  26. // macros
  27. // ----------------------------------------------------------------------------
  28. // this macro may be used instead for wxDropSource ctor arguments: it will use
  29. // the icon 'name' from an XPM file under GTK, but will expand to something
  30. // else under MSW. If you don't use it, you will have to use #ifdef in the
  31. // application code.
  32. #define wxDROP_ICON(name) wxICON(name)
  33. //-------------------------------------------------------------------------
  34. // wxDropTarget
  35. //-------------------------------------------------------------------------
  36. class WXDLLIMPEXP_CORE wxDropTarget: public wxDropTargetBase
  37. {
  38. public:
  39. wxDropTarget(wxDataObject *dataObject = NULL );
  40. virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
  41. virtual bool OnDrop(wxCoord x, wxCoord y);
  42. virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
  43. virtual bool GetData();
  44. // implementation
  45. GdkAtom GetMatchingPair(bool quiet = false);
  46. void RegisterWidget( GtkWidget *widget );
  47. void UnregisterWidget( GtkWidget *widget );
  48. GdkDragContext *m_dragContext;
  49. GtkWidget *m_dragWidget;
  50. GtkSelectionData *m_dragData;
  51. unsigned m_dragTime;
  52. bool m_firstMotion; // gdk has no "gdk_drag_enter" event
  53. void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
  54. void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
  55. void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
  56. void SetDragTime(unsigned time) { m_dragTime = time; }
  57. };
  58. //-------------------------------------------------------------------------
  59. // wxDropSource
  60. //-------------------------------------------------------------------------
  61. class WXDLLIMPEXP_CORE wxDropSource: public wxDropSourceBase
  62. {
  63. public:
  64. // constructor. set data later with SetData()
  65. wxDropSource( wxWindow *win = NULL,
  66. const wxIcon &copy = wxNullIcon,
  67. const wxIcon &move = wxNullIcon,
  68. const wxIcon &none = wxNullIcon);
  69. // constructor for setting one data object
  70. wxDropSource( wxDataObject& data,
  71. wxWindow *win,
  72. const wxIcon &copy = wxNullIcon,
  73. const wxIcon &move = wxNullIcon,
  74. const wxIcon &none = wxNullIcon);
  75. virtual ~wxDropSource();
  76. // start drag action
  77. virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
  78. // GTK implementation
  79. void RegisterWindow();
  80. void UnregisterWindow();
  81. void PrepareIcon( int action, GdkDragContext *context );
  82. GtkWidget *m_widget;
  83. GtkWidget *m_iconWindow;
  84. GdkDragContext *m_dragContext;
  85. wxWindow *m_window;
  86. wxDragResult m_retValue;
  87. wxIcon m_iconCopy,
  88. m_iconMove,
  89. m_iconNone;
  90. bool m_waiting;
  91. private:
  92. // common part of both ctors
  93. void SetIcons(const wxIcon& copy,
  94. const wxIcon& move,
  95. const wxIcon& none);
  96. };
  97. #endif // wxUSE_DRAG_AND_DROP
  98. #endif //__GTKDNDH__