SDL_clipboard.h 8.3 KB

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