SDL_clipboard.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * # CategoryClipboard
  20. *
  21. * SDL provides access to the system clipboard, both for reading information
  22. * from other processes and publishing information of its own.
  23. *
  24. * This is not just text! SDL apps can access and publish data by mimetype.
  25. */
  26. #ifndef SDL_clipboard_h_
  27. #define SDL_clipboard_h_
  28. #include <SDL3/SDL_stdinc.h>
  29. #include <SDL3/SDL_error.h>
  30. #include <SDL3/SDL_begin_code.h>
  31. /* Set up for C function definitions, even when using C++ */
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /* Function prototypes */
  36. /**
  37. * Put UTF-8 text into the clipboard.
  38. *
  39. * \param text the text to store in the clipboard.
  40. * \returns 0 on success or a negative error code on failure; call
  41. * SDL_GetError() for more information.
  42. *
  43. * \since This function is available since SDL 3.0.0.
  44. *
  45. * \sa SDL_GetClipboardText
  46. * \sa SDL_HasClipboardText
  47. */
  48. extern SDL_DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
  49. /**
  50. * Get UTF-8 text from the clipboard.
  51. *
  52. * This functions returns empty string if there was not enough memory left for
  53. * a copy of the clipboard's content.
  54. *
  55. * This returns temporary memory which will be automatically freed later, and
  56. * can be claimed with SDL_ClaimTemporaryMemory().
  57. *
  58. * \returns the clipboard text on success or an empty string on failure; call
  59. * SDL_GetError() for more information.
  60. *
  61. * \since This function is available since SDL 3.0.0.
  62. *
  63. * \sa SDL_HasClipboardText
  64. * \sa SDL_SetClipboardText
  65. */
  66. extern SDL_DECLSPEC const char * SDLCALL SDL_GetClipboardText(void);
  67. /**
  68. * Query whether the clipboard exists and contains a non-empty text string.
  69. *
  70. * \returns SDL_TRUE if the clipboard has text, or SDL_FALSE if it does not.
  71. *
  72. * \since This function is available since SDL 3.0.0.
  73. *
  74. * \sa SDL_GetClipboardText
  75. * \sa SDL_SetClipboardText
  76. */
  77. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
  78. /**
  79. * Put UTF-8 text into the primary selection.
  80. *
  81. * \param text the text to store in the primary selection.
  82. * \returns 0 on success or a negative error code on failure; call
  83. * SDL_GetError() for more information.
  84. *
  85. * \since This function is available since SDL 3.0.0.
  86. *
  87. * \sa SDL_GetPrimarySelectionText
  88. * \sa SDL_HasPrimarySelectionText
  89. */
  90. extern SDL_DECLSPEC int SDLCALL SDL_SetPrimarySelectionText(const char *text);
  91. /**
  92. * Get UTF-8 text from the primary selection.
  93. *
  94. * This functions returns empty string if there was not enough memory left for
  95. * a copy of the primary selection's content.
  96. *
  97. * This returns temporary memory which will be automatically freed later, and
  98. * can be claimed with SDL_ClaimTemporaryMemory().
  99. *
  100. * \returns the primary selection text on success or an empty string on
  101. * failure; call SDL_GetError() for more information.
  102. *
  103. * \since This function is available since SDL 3.0.0.
  104. *
  105. * \sa SDL_HasPrimarySelectionText
  106. * \sa SDL_SetPrimarySelectionText
  107. */
  108. extern SDL_DECLSPEC const char * SDLCALL SDL_GetPrimarySelectionText(void);
  109. /**
  110. * Query whether the primary selection exists and contains a non-empty text
  111. * string.
  112. *
  113. * \returns SDL_TRUE if the primary selection has text, or SDL_FALSE if it
  114. * does not.
  115. *
  116. * \since This function is available since SDL 3.0.0.
  117. *
  118. * \sa SDL_GetPrimarySelectionText
  119. * \sa SDL_SetPrimarySelectionText
  120. */
  121. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasPrimarySelectionText(void);
  122. /**
  123. * Callback function that will be called when data for the specified mime-type
  124. * is requested by the OS.
  125. *
  126. * The callback function is called with NULL as the mime_type when the
  127. * clipboard is cleared or new data is set. The clipboard is automatically
  128. * cleared in SDL_Quit().
  129. *
  130. * \param userdata a pointer to provided user data.
  131. * \param mime_type the requested mime-type.
  132. * \param size a pointer filled in with the length of the returned data.
  133. * \returns a pointer to the data for the provided mime-type. Returning NULL
  134. * or setting length to 0 will cause no data to be sent to the
  135. * "receiver". It is up to the receiver to handle this. Essentially
  136. * returning no data is more or less undefined behavior and may cause
  137. * breakage in receiving applications. The returned data will not be
  138. * freed so it needs to be retained and dealt with internally.
  139. *
  140. * \since This function is available since SDL 3.0.0.
  141. *
  142. * \sa SDL_SetClipboardData
  143. */
  144. typedef const void *(SDLCALL *SDL_ClipboardDataCallback)(void *userdata, const char *mime_type, size_t *size);
  145. /**
  146. * Callback function that will be called when the clipboard is cleared, or new
  147. * data is set.
  148. *
  149. * \param userdata a pointer to provided user data.
  150. *
  151. * \since This function is available since SDL 3.0.0.
  152. *
  153. * \sa SDL_SetClipboardData
  154. */
  155. typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
  156. /**
  157. * Offer clipboard data to the OS.
  158. *
  159. * Tell the operating system that the application is offering clipboard data
  160. * for each of the proivded mime-types. Once another application requests the
  161. * data the callback function will be called allowing it to generate and
  162. * respond with the data for the requested mime-type.
  163. *
  164. * The size of text data does not include any terminator, and the text does
  165. * not need to be null terminated (e.g. you can directly copy a portion of a
  166. * document)
  167. *
  168. * \param callback a function pointer to the function that provides the
  169. * clipboard data.
  170. * \param cleanup a function pointer to the function that cleans up the
  171. * clipboard data.
  172. * \param userdata an opaque pointer that will be forwarded to the callbacks.
  173. * \param mime_types a list of mime-types that are being offered.
  174. * \param num_mime_types the number of mime-types in the mime_types list.
  175. * \returns 0 on success or a negative error code on failure; call
  176. * SDL_GetError() for more information.
  177. *
  178. * \since This function is available since SDL 3.0.0.
  179. *
  180. * \sa SDL_ClearClipboardData
  181. * \sa SDL_GetClipboardData
  182. * \sa SDL_HasClipboardData
  183. */
  184. extern SDL_DECLSPEC int SDLCALL SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types);
  185. /**
  186. * Clear the clipboard data.
  187. *
  188. * \returns 0 on success or a negative error code on failure; call
  189. * SDL_GetError() for more information.
  190. *
  191. * \since This function is available since SDL 3.0.0.
  192. *
  193. * \sa SDL_SetClipboardData
  194. */
  195. extern SDL_DECLSPEC int SDLCALL SDL_ClearClipboardData(void);
  196. /**
  197. * Get the data from clipboard for a given mime type.
  198. *
  199. * The size of text data does not include the terminator, but the text is
  200. * guaranteed to be null terminated.
  201. *
  202. * \param mime_type the mime type to read from the clipboard.
  203. * \param size a pointer filled in with the length of the returned data.
  204. * \returns the retrieved data buffer or NULL on failure; call SDL_GetError()
  205. * for more information.
  206. *
  207. * This returns temporary memory which will be automatically freed
  208. * later, and can be claimed with SDL_ClaimTemporaryMemory().
  209. *
  210. * \since This function is available since SDL 3.0.0.
  211. *
  212. * \sa SDL_HasClipboardData
  213. * \sa SDL_SetClipboardData
  214. */
  215. extern SDL_DECLSPEC const void * SDLCALL SDL_GetClipboardData(const char *mime_type, size_t *size);
  216. /**
  217. * Query whether there is data in the clipboard for the provided mime type.
  218. *
  219. * \param mime_type the mime type to check for data for.
  220. * \returns SDL_TRUE if there exists data in clipboard for the provided mime
  221. * type, SDL_FALSE if it does not.
  222. *
  223. * \since This function is available since SDL 3.0.0.
  224. *
  225. * \sa SDL_SetClipboardData
  226. * \sa SDL_GetClipboardData
  227. */
  228. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardData(const char *mime_type);
  229. /* Ends C function definitions when using C++ */
  230. #ifdef __cplusplus
  231. }
  232. #endif
  233. #include <SDL3/SDL_close_code.h>
  234. #endif /* SDL_clipboard_h_ */