clipbrd.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/clipbrd.h
  3. // Purpose: wxClipboard for wxGTK
  4. // Author: Robert Roebling, Vadim Zeitlin
  5. // Copyright: (c) 1998 Robert Roebling
  6. // (c) 2007 Vadim Zeitlin
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_GTK_CLIPBOARD_H_
  10. #define _WX_GTK_CLIPBOARD_H_
  11. // ----------------------------------------------------------------------------
  12. // wxClipboard
  13. // ----------------------------------------------------------------------------
  14. #include "wx/weakref.h"
  15. class WXDLLIMPEXP_CORE wxClipboard : public wxClipboardBase
  16. {
  17. public:
  18. // there are several clipboards in X11 (and in GDK)
  19. enum Kind
  20. {
  21. Primary,
  22. Clipboard
  23. };
  24. wxClipboard();
  25. virtual ~wxClipboard();
  26. // open the clipboard before SetData() and GetData()
  27. virtual bool Open();
  28. // close the clipboard after SetData() and GetData()
  29. virtual void Close();
  30. // query whether the clipboard is opened
  31. virtual bool IsOpened() const;
  32. // set the clipboard data. all other formats will be deleted.
  33. virtual bool SetData( wxDataObject *data );
  34. // add to the clipboard data.
  35. virtual bool AddData( wxDataObject *data );
  36. // ask if data in correct format is available
  37. virtual bool IsSupported( const wxDataFormat& format );
  38. // ask if data in correct format is available
  39. virtual bool IsSupportedAsync( wxEvtHandler *sink );
  40. // fill data with data on the clipboard (if available)
  41. virtual bool GetData( wxDataObject& data );
  42. // clears wxTheClipboard and the system's clipboard if possible
  43. virtual void Clear();
  44. // implementation from now on
  45. // --------------------------
  46. // get our clipboard item (depending on m_usePrimary value)
  47. GdkAtom GTKGetClipboardAtom() const;
  48. // get the data object currently being requested
  49. wxDataObject *GTKGetDataObject( GdkAtom atom );
  50. // clear the data for the given clipboard kind
  51. void GTKClearData(Kind kind);
  52. // called when selection data is received
  53. void GTKOnSelectionReceived(const GtkSelectionData& sel);
  54. // called when available target information is received
  55. bool GTKOnTargetReceived(const wxDataFormat& format);
  56. private:
  57. // the data object for the specific selection
  58. wxDataObject *& Data(Kind kind)
  59. {
  60. return kind == Primary ? m_dataPrimary : m_dataClipboard;
  61. }
  62. // the data object we're currently using
  63. wxDataObject *& Data()
  64. {
  65. return Data(m_usePrimary ? Primary : Clipboard);
  66. }
  67. // set or unset selection ownership
  68. bool SetSelectionOwner(bool set = true);
  69. // add atom to the list of supported targets
  70. void AddSupportedTarget(GdkAtom atom);
  71. // check if the given format is supported
  72. bool DoIsSupported(const wxDataFormat& format);
  73. // both of these pointers can be non-NULL simultaneously but we only use
  74. // one of them at any moment depending on m_usePrimary value, use Data()
  75. // (from inside) or GTKGetDataObject() (from outside) accessors
  76. wxDataObject *m_dataPrimary,
  77. *m_dataClipboard;
  78. // this is used to temporarily hold the object passed to our GetData() so
  79. // that GTK callbacks could access it
  80. wxDataObject *m_receivedData;
  81. // used to pass information about the format we need from DoIsSupported()
  82. // to GTKOnTargetReceived()
  83. GdkAtom m_targetRequested;
  84. GtkWidget *m_clipboardWidget; // for getting and offering data
  85. GtkWidget *m_targetsWidget; // for getting list of supported formats
  86. // ID of the connection to "selection_get" signal, initially 0.
  87. unsigned long m_idSelectionGetHandler;
  88. bool m_open;
  89. bool m_formatSupported;
  90. public:
  91. // async stuff
  92. wxEvtHandlerRef m_sink;
  93. private:
  94. GtkWidget *m_targetsWidgetAsync; // for getting list of supported formats
  95. DECLARE_DYNAMIC_CLASS(wxClipboard)
  96. };
  97. #endif // _WX_GTK_CLIPBOARD_H_