clipbrd.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: clipbrd.h
  3. // Purpose: interface of wxClipboard
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. The backwards compatible access macro that returns the global clipboard
  9. object pointer.
  10. */
  11. #define wxTheClipboard
  12. /**
  13. @class wxClipboard
  14. A class for manipulating the clipboard.
  15. To use the clipboard, you call member functions of the global
  16. ::wxTheClipboard object.
  17. See the @ref overview_dataobject for further information.
  18. Call wxClipboard::Open() to get ownership of the clipboard. If this
  19. operation returns @true, you now own the clipboard. Call
  20. wxClipboard::SetData() to put data on the clipboard, or
  21. wxClipboard::GetData() to retrieve data from the clipboard. Call
  22. wxClipboard::Close() to close the clipboard and relinquish ownership. You
  23. should keep the clipboard open only momentarily.
  24. For example:
  25. @code
  26. // Write some text to the clipboard
  27. if (wxTheClipboard->Open())
  28. {
  29. // This data objects are held by the clipboard,
  30. // so do not delete them in the app.
  31. wxTheClipboard->SetData( new wxTextDataObject("Some text") );
  32. wxTheClipboard->Close();
  33. }
  34. // Read some text
  35. if (wxTheClipboard->Open())
  36. {
  37. if (wxTheClipboard->IsSupported( wxDF_TEXT ))
  38. {
  39. wxTextDataObject data;
  40. wxTheClipboard->GetData( data );
  41. wxMessageBox( data.GetText() );
  42. }
  43. wxTheClipboard->Close();
  44. }
  45. @endcode
  46. @library{wxcore}
  47. @category{dnd}
  48. @see @ref overview_dnd, @ref overview_dataobject, wxDataObject
  49. */
  50. class wxClipboard : public wxObject
  51. {
  52. public:
  53. /**
  54. Default constructor.
  55. */
  56. wxClipboard();
  57. /**
  58. Destructor.
  59. */
  60. virtual ~wxClipboard();
  61. /**
  62. Call this function to add the data object to the clipboard. You may
  63. call this function repeatedly after having cleared the clipboard using
  64. Clear().
  65. After this function has been called, the clipboard owns the data, so do
  66. not delete the data explicitly.
  67. @see SetData()
  68. */
  69. virtual bool AddData(wxDataObject* data);
  70. /**
  71. Clears the global clipboard object and the system's clipboard if
  72. possible.
  73. */
  74. virtual void Clear();
  75. /**
  76. Call this function to close the clipboard, having opened it with
  77. Open().
  78. */
  79. virtual void Close();
  80. /**
  81. Flushes the clipboard: this means that the data which is currently on
  82. clipboard will stay available even after the application exits
  83. (possibly eating memory), otherwise the clipboard will be emptied on
  84. exit.
  85. Currently this method is not implemented in X11-based ports, i.e.
  86. wxGTK, wxX11 and wxMotif and always returns @false there.
  87. @return @false if the operation is unsuccessful for any reason.
  88. */
  89. virtual bool Flush();
  90. /**
  91. Call this function to fill @a data with data on the clipboard, if
  92. available in the required format. Returns @true on success.
  93. */
  94. virtual bool GetData(wxDataObject& data);
  95. /**
  96. Returns @true if the clipboard has been opened.
  97. */
  98. virtual bool IsOpened() const;
  99. /**
  100. Returns @true if there is data which matches the data format of the
  101. given data object currently @b available on the clipboard.
  102. @todo The name of this function is misleading. This should be renamed
  103. to something that more accurately indicates what it does.
  104. */
  105. virtual bool IsSupported(const wxDataFormat& format);
  106. /**
  107. Returns @true if we are using the primary selection, @false if
  108. clipboard one.
  109. @see UsePrimarySelection()
  110. */
  111. bool IsUsingPrimarySelection() const;
  112. /**
  113. Call this function to open the clipboard before calling SetData() and
  114. GetData().
  115. Call Close() when you have finished with the clipboard. You should keep
  116. the clipboard open for only a very short time.
  117. @return @true on success. This should be tested (as in the sample
  118. shown above).
  119. */
  120. virtual bool Open();
  121. /**
  122. Call this function to set the data object to the clipboard. This
  123. function will clear all previous contents in the clipboard, so calling
  124. it several times does not make any sense.
  125. After this function has been called, the clipboard owns the data, so do
  126. not delete the data explicitly.
  127. @see AddData()
  128. */
  129. virtual bool SetData(wxDataObject* data);
  130. /**
  131. On platforms supporting it (all X11-based ports), wxClipboard uses the
  132. CLIPBOARD X11 selection by default. When this function is called with
  133. @true, all subsequent clipboard operations will use PRIMARY selection
  134. until this function is called again with @false.
  135. On the other platforms, there is no PRIMARY selection and so all
  136. clipboard operations will fail. This allows to implement the standard
  137. X11 handling of the clipboard which consists in copying data to the
  138. CLIPBOARD selection only when the user explicitly requests it (i.e. by
  139. selecting the "Copy" menu command) but putting the currently selected
  140. text into the PRIMARY selection automatically, without overwriting the
  141. normal clipboard contents with the currently selected text on the other
  142. platforms.
  143. */
  144. virtual void UsePrimarySelection(bool primary = false);
  145. /**
  146. Returns the global instance (wxTheClipboard) of the clipboard object.
  147. */
  148. static wxClipboard *Get();
  149. };