SDL_clipboard.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  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 DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
  49. /**
  50. * Get UTF-8 text from the clipboard, which must be freed with SDL_free().
  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. * \returns the clipboard text on success or an empty string on failure; call
  56. * SDL_GetError() for more information. Caller must call SDL_free()
  57. * on the returned pointer when done with it (even if there was an
  58. * error).
  59. *
  60. * \since This function is available since SDL 3.0.0.
  61. *
  62. * \sa SDL_HasClipboardText
  63. * \sa SDL_SetClipboardText
  64. */
  65. extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void);
  66. /**
  67. * Query whether the clipboard exists and contains a non-empty text string.
  68. *
  69. * \returns SDL_TRUE if the clipboard has text, or SDL_FALSE if it does not.
  70. *
  71. * \since This function is available since SDL 3.0.0.
  72. *
  73. * \sa SDL_GetClipboardText
  74. * \sa SDL_SetClipboardText
  75. */
  76. extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void);
  77. /**
  78. * Put UTF-8 text into the primary selection.
  79. *
  80. * \param text the text to store in the primary selection
  81. * \returns 0 on success or a negative error code on failure; call
  82. * SDL_GetError() for more information.
  83. *
  84. * \since This function is available since SDL 3.0.0.
  85. *
  86. * \sa SDL_GetPrimarySelectionText
  87. * \sa SDL_HasPrimarySelectionText
  88. */
  89. extern DECLSPEC int SDLCALL SDL_SetPrimarySelectionText(const char *text);
  90. /**
  91. * Get UTF-8 text from the primary selection, which must be freed with
  92. * SDL_free().
  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. * \returns the primary selection text on success or an empty string on
  98. * failure; call SDL_GetError() for more information. Caller must
  99. * call SDL_free() on the returned pointer when done with it (even if
  100. * there was an error).
  101. *
  102. * \since This function is available since SDL 3.0.0.
  103. *
  104. * \sa SDL_HasPrimarySelectionText
  105. * \sa SDL_SetPrimarySelectionText
  106. */
  107. extern DECLSPEC char * SDLCALL SDL_GetPrimarySelectionText(void);
  108. /**
  109. * Query whether the primary selection exists and contains a non-empty text
  110. * string.
  111. *
  112. * \returns SDL_TRUE if the primary selection has text, or SDL_FALSE if it
  113. * does not.
  114. *
  115. * \since This function is available since SDL 3.0.0.
  116. *
  117. * \sa SDL_GetPrimarySelectionText
  118. * \sa SDL_SetPrimarySelectionText
  119. */
  120. extern DECLSPEC SDL_bool SDLCALL SDL_HasPrimarySelectionText(void);
  121. /**
  122. * Callback function that will be called when data for the specified mime-type
  123. * is requested by the OS.
  124. *
  125. * The callback function is called with NULL as the mime_type when the
  126. * clipboard is cleared or new data is set. The clipboard is automatically
  127. * cleared in SDL_Quit().
  128. *
  129. * \param userdata A pointer to provided user data
  130. * \param mime_type The requested mime-type
  131. * \param size A pointer filled in with the length of the returned data
  132. * \returns a pointer to the data for the provided mime-type. Returning NULL
  133. * or setting length to 0 will cause no data to be sent to the
  134. * "receiver". It is up to the receiver to handle this. Essentially
  135. * returning no data is more or less undefined behavior and may cause
  136. * breakage in receiving applications. The returned data will not be
  137. * freed so it needs to be retained and dealt with internally.
  138. *
  139. * \since This function is available since SDL 3.0.0.
  140. *
  141. * \sa SDL_SetClipboardData
  142. */
  143. typedef const void *(SDLCALL *SDL_ClipboardDataCallback)(void *userdata, const char *mime_type, size_t *size);
  144. /**
  145. * Callback function that will be called when the clipboard is cleared, or new
  146. * data is set.
  147. *
  148. * \param userdata A pointer to provided user data
  149. *
  150. * \since This function is available since SDL 3.0.0.
  151. *
  152. * \sa SDL_SetClipboardData
  153. */
  154. typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata);
  155. /**
  156. * Offer clipboard data to the OS.
  157. *
  158. * Tell the operating system that the application is offering clipboard data
  159. * for each of the proivded mime-types. Once another application requests the
  160. * data the callback function will be called allowing it to generate and
  161. * respond with the data for the requested mime-type.
  162. *
  163. * The size of text data does not include any terminator, and the text does
  164. * not need to be null terminated (e.g. you can directly copy a portion of a
  165. * document)
  166. *
  167. * \param callback A function pointer to the function that provides the
  168. * clipboard data
  169. * \param cleanup A function pointer to the function that cleans up the
  170. * clipboard data
  171. * \param userdata An opaque pointer that will be forwarded to the callbacks
  172. * \param mime_types A list of mime-types that are being offered
  173. * \param num_mime_types The number of mime-types in the mime_types list
  174. * \returns 0 on success or a negative error code on failure; call
  175. * SDL_GetError() for more information.
  176. *
  177. * \since This function is available since SDL 3.0.0.
  178. *
  179. * \sa SDL_ClearClipboardData
  180. * \sa SDL_GetClipboardData
  181. * \sa SDL_HasClipboardData
  182. */
  183. extern DECLSPEC int SDLCALL SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types);
  184. /**
  185. * Clear the clipboard data.
  186. *
  187. * \returns 0 on success or a negative error code on failure; call
  188. * SDL_GetError() for more information.
  189. *
  190. * \since This function is available since SDL 3.0.0.
  191. *
  192. * \sa SDL_SetClipboardData
  193. */
  194. extern DECLSPEC int SDLCALL SDL_ClearClipboardData(void);
  195. /**
  196. * Get the data from clipboard for a given mime type.
  197. *
  198. * The size of text data does not include the terminator, but the text is
  199. * guaranteed to be null terminated.
  200. *
  201. * \param mime_type The mime type to read from the clipboard
  202. * \param size A pointer filled in with the length of the returned data
  203. * \returns the retrieved data buffer or NULL on failure; call SDL_GetError()
  204. * for more information. Caller must call SDL_free() on the returned
  205. * pointer when done with it.
  206. *
  207. * \since This function is available since SDL 3.0.0.
  208. *
  209. * \sa SDL_HasClipboardData
  210. * \sa SDL_SetClipboardData
  211. */
  212. extern DECLSPEC void *SDLCALL SDL_GetClipboardData(const char *mime_type, size_t *size);
  213. /**
  214. * Query whether there is data in the clipboard for the provided mime type.
  215. *
  216. * \param mime_type The mime type to check for data for
  217. * \returns SDL_TRUE if there exists data in clipboard for the provided mime
  218. * type, SDL_FALSE if it does not.
  219. *
  220. * \since This function is available since SDL 3.0.0.
  221. *
  222. * \sa SDL_SetClipboardData
  223. * \sa SDL_GetClipboardData
  224. */
  225. extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardData(const char *mime_type);
  226. /* Ends C function definitions when using C++ */
  227. #ifdef __cplusplus
  228. }
  229. #endif
  230. #include <SDL3/SDL_close_code.h>
  231. #endif /* SDL_clipboard_h_ */