SDL_clipboard.h 8.4 KB

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