dnd.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/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 _WX_GTK_DND_H_
  9. #define _WX_GTK_DND_H_
  10. #include "wx/icon.h"
  11. // ----------------------------------------------------------------------------
  12. // macros
  13. // ----------------------------------------------------------------------------
  14. // this macro may be used instead for wxDropSource ctor arguments: it will use
  15. // the icon 'name' from an XPM file under GTK, but will expand to something
  16. // else under MSW. If you don't use it, you will have to use #ifdef in the
  17. // application code.
  18. #define wxDROP_ICON(name) wxICON(name)
  19. //-------------------------------------------------------------------------
  20. // wxDropTarget
  21. //-------------------------------------------------------------------------
  22. class WXDLLIMPEXP_CORE wxDropTarget: public wxDropTargetBase
  23. {
  24. public:
  25. wxDropTarget(wxDataObject *dataObject = NULL );
  26. virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def);
  27. virtual bool OnDrop(wxCoord x, wxCoord y);
  28. virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def);
  29. virtual bool GetData();
  30. // Can only be called during OnXXX methods.
  31. wxDataFormat GetMatchingPair();
  32. // implementation
  33. GdkAtom GTKGetMatchingPair(bool quiet = false);
  34. wxDragResult GTKFigureOutSuggestedAction();
  35. void GtkRegisterWidget( GtkWidget *widget );
  36. void GtkUnregisterWidget( GtkWidget *widget );
  37. GdkDragContext *m_dragContext;
  38. GtkWidget *m_dragWidget;
  39. GtkSelectionData *m_dragData;
  40. unsigned m_dragTime;
  41. bool m_firstMotion; // gdk has no "gdk_drag_enter" event
  42. void GTKSetDragContext( GdkDragContext *dc ) { m_dragContext = dc; }
  43. void GTKSetDragWidget( GtkWidget *w ) { m_dragWidget = w; }
  44. void GTKSetDragData( GtkSelectionData *sd ) { m_dragData = sd; }
  45. void GTKSetDragTime(unsigned time) { m_dragTime = time; }
  46. };
  47. //-------------------------------------------------------------------------
  48. // wxDropSource
  49. //-------------------------------------------------------------------------
  50. class WXDLLIMPEXP_CORE wxDropSource: public wxDropSourceBase
  51. {
  52. public:
  53. // constructor. set data later with SetData()
  54. wxDropSource( wxWindow *win = NULL,
  55. const wxIcon &copy = wxNullIcon,
  56. const wxIcon &move = wxNullIcon,
  57. const wxIcon &none = wxNullIcon);
  58. // constructor for setting one data object
  59. wxDropSource( wxDataObject& data,
  60. wxWindow *win,
  61. const wxIcon &copy = wxNullIcon,
  62. const wxIcon &move = wxNullIcon,
  63. const wxIcon &none = wxNullIcon);
  64. virtual ~wxDropSource();
  65. // set the icon corresponding to given drag result
  66. void SetIcon(wxDragResult res, const wxIcon& icon)
  67. {
  68. if ( res == wxDragCopy )
  69. m_iconCopy = icon;
  70. else if ( res == wxDragMove )
  71. m_iconMove = icon;
  72. else
  73. m_iconNone = icon;
  74. }
  75. // start drag action
  76. virtual wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly);
  77. void PrepareIcon( int action, GdkDragContext *context );
  78. GtkWidget *m_widget;
  79. GtkWidget *m_iconWindow;
  80. GdkDragContext *m_dragContext;
  81. wxWindow *m_window;
  82. wxDragResult m_retValue;
  83. wxIcon m_iconCopy,
  84. m_iconMove,
  85. m_iconNone;
  86. bool m_waiting;
  87. private:
  88. // common part of both ctors
  89. void SetIcons(const wxIcon& copy,
  90. const wxIcon& move,
  91. const wxIcon& none);
  92. // GTK implementation
  93. void GTKConnectDragSignals();
  94. void GTKDisconnectDragSignals();
  95. };
  96. #endif // _WX_GTK_DND_H_