|
| 1 | +{ |
| 2 | + This file is part of: |
| 3 | +
|
| 4 | + SDL3 for Pascal |
| 5 | + (https://github.com/PascalGameDevelopment/SDL3-for-Pascal) |
| 6 | + SPDX-License-Identifier: Zlib |
| 7 | +} |
| 8 | + |
| 9 | +{* |
| 10 | + * # CategoryClipboard |
| 11 | + * |
| 12 | + * SDL provides access to the system clipboard, both for reading information |
| 13 | + * from other processes and publishing information of its own. |
| 14 | + * |
| 15 | + * This is not just text! SDL apps can access and publish data by mimetype. |
| 16 | + } |
| 17 | + |
| 18 | +{ Function prototypes } |
| 19 | + |
| 20 | +{* |
| 21 | + * Put UTF-8 text into the clipboard. |
| 22 | + * |
| 23 | + * \param text the text to store in the clipboard. |
| 24 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 25 | + * information. |
| 26 | + * |
| 27 | + * \threadsafety You may only call this function from the main thread. |
| 28 | + * |
| 29 | + * \since This function is available since SDL 3.1.3. |
| 30 | + * |
| 31 | + * \sa SDL_GetClipboardText |
| 32 | + * \sa SDL_HasClipboardText |
| 33 | + } |
| 34 | +function SDL_SetClipboardText(text: PAnsiChar): cbool; cdecl; |
| 35 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetClipboardText' {$ENDIF} {$ENDIF}; |
| 36 | + |
| 37 | +{* |
| 38 | + * Get UTF-8 text from the clipboard. |
| 39 | + * |
| 40 | + * This functions returns an empty string if there was not enough memory left |
| 41 | + * for a copy of the clipboard's content. |
| 42 | + * |
| 43 | + * \returns the clipboard text on success or an empty string on failure; call |
| 44 | + * SDL_GetError() for more information. This should be freed with |
| 45 | + * SDL_free() when it is no longer needed. |
| 46 | + * |
| 47 | + * \threadsafety You may only call this function from the main thread. |
| 48 | + * |
| 49 | + * \since This function is available since SDL 3.1.3. |
| 50 | + * |
| 51 | + * \sa SDL_HasClipboardText |
| 52 | + * \sa SDL_SetClipboardText |
| 53 | + } |
| 54 | +function SDL_GetClipboardText: PAnsiChar; cdecl; |
| 55 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetClipboardText' {$ENDIF} {$ENDIF}; |
| 56 | + |
| 57 | +{* |
| 58 | + * Query whether the clipboard exists and contains a non-empty text string. |
| 59 | + * |
| 60 | + * \returns true if the clipboard has text, or false if it does not. |
| 61 | + * |
| 62 | + * \threadsafety You may only call this function from the main thread. |
| 63 | + * |
| 64 | + * \since This function is available since SDL 3.1.3. |
| 65 | + * |
| 66 | + * \sa SDL_GetClipboardText |
| 67 | + * \sa SDL_SetClipboardText |
| 68 | + } |
| 69 | +function SDL_HasClipboardText: cbool; cdecl; |
| 70 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasClipboardText' {$ENDIF} {$ENDIF}; |
| 71 | + |
| 72 | +{* |
| 73 | + * Put UTF-8 text into the primary selection. |
| 74 | + * |
| 75 | + * \param text the text to store in the primary selection. |
| 76 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 77 | + * information. |
| 78 | + * |
| 79 | + * \threadsafety You may only call this function from the main thread. |
| 80 | + * |
| 81 | + * \since This function is available since SDL 3.1.3. |
| 82 | + * |
| 83 | + * \sa SDL_GetPrimarySelectionText |
| 84 | + * \sa SDL_HasPrimarySelectionText |
| 85 | + } |
| 86 | +function SDL_SetPrimarySelectionText(text: PAnsiChar): cbool; cdecl; |
| 87 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetPrimarySelectionText' {$ENDIF} {$ENDIF}; |
| 88 | + |
| 89 | +{* |
| 90 | + * Get UTF-8 text from the primary selection. |
| 91 | + * |
| 92 | + * This functions returns an empty string if there was not enough memory left |
| 93 | + * for a copy of the primary selection's content. |
| 94 | + * |
| 95 | + * \returns the primary selection text on success or an empty string on |
| 96 | + * failure; call SDL_GetError() for more information. This should be |
| 97 | + * freed with SDL_free() when it is no longer needed. |
| 98 | + * |
| 99 | + * \threadsafety You may only call this function from the main thread. |
| 100 | + * |
| 101 | + * \since This function is available since SDL 3.1.3. |
| 102 | + * |
| 103 | + * \sa SDL_HasPrimarySelectionText |
| 104 | + * \sa SDL_SetPrimarySelectionText |
| 105 | + } |
| 106 | +function SDL_GetPrimarySelectionText: PAnsiChar; cdecl; |
| 107 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetPrimarySelectionText' {$ENDIF} {$ENDIF}; |
| 108 | + |
| 109 | +{* |
| 110 | + * Query whether the primary selection exists and contains a non-empty text |
| 111 | + * string. |
| 112 | + * |
| 113 | + * \returns true if the primary selection has text, or false if it does not. |
| 114 | + * |
| 115 | + * \threadsafety You may only call this function from the main thread. |
| 116 | + * |
| 117 | + * \since This function is available since SDL 3.1.3. |
| 118 | + * |
| 119 | + * \sa SDL_GetPrimarySelectionText |
| 120 | + * \sa SDL_SetPrimarySelectionText |
| 121 | + } |
| 122 | +function SDL_HasPrimarySelectionText: cbool; cdecl; |
| 123 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasPrimarySelectionText' {$ENDIF} {$ENDIF}; |
| 124 | + |
| 125 | +{* |
| 126 | + * Callback function that will be called when data for the specified mime-type |
| 127 | + * is requested by the OS. |
| 128 | + * |
| 129 | + * The callback function is called with nil as the mime_type when the |
| 130 | + * clipboard is cleared or new data is set. The clipboard is automatically |
| 131 | + * cleared in SDL_Quit(). |
| 132 | + * |
| 133 | + * \param userdata a Pointer to provided user data. |
| 134 | + * \param mime_type the requested mime-type. |
| 135 | + * \param size a Pointer filled in with the length of the returned data. |
| 136 | + * \returns a Pointer to the data for the provided mime-type. Returning nil |
| 137 | + * or setting length to 0 will cause no data to be sent to the |
| 138 | + * "receiver". It is up to the receiver to handle this. Essentially |
| 139 | + * returning no data is more or less undefined behavior and may cause |
| 140 | + * breakage in receiving applications. The returned data will not be |
| 141 | + * freed so it needs to be retained and dealt with internally. |
| 142 | + * |
| 143 | + * \since This function is available since SDL 3.1.3. |
| 144 | + * |
| 145 | + * \sa SDL_SetClipboardData |
| 146 | + } |
| 147 | +type |
| 148 | + TSDL_ClipboardDataCallback = function(userdata: Pointer; mime_type: PAnsiChar; size: psize_t): Pointer; cdecl; |
| 149 | + |
| 150 | +{* |
| 151 | + * Callback function that will be called when the clipboard is cleared, or new |
| 152 | + * data is set. |
| 153 | + * |
| 154 | + * \param userdata a Pointer to provided user data. |
| 155 | + * |
| 156 | + * \since This function is available since SDL 3.1.3. |
| 157 | + * |
| 158 | + * \sa SDL_SetClipboardData |
| 159 | + } |
| 160 | +type |
| 161 | + TSDL_ClipboardCleanupCallback = procedure(userdata: Pointer); cdecl; |
| 162 | + |
| 163 | +{* |
| 164 | + * Offer clipboard data to the OS. |
| 165 | + * |
| 166 | + * Tell the operating system that the application is offering clipboard data |
| 167 | + * for each of the proivded mime-types. Once another application requests the |
| 168 | + * data the callback function will be called allowing it to generate and |
| 169 | + * respond with the data for the requested mime-type. |
| 170 | + * |
| 171 | + * The size of text data does not include any terminator, and the text does |
| 172 | + * not need to be null terminated (e.g. you can directly copy a portion of a |
| 173 | + * document) |
| 174 | + * |
| 175 | + * \param callback a function Pointer to the function that provides the |
| 176 | + * clipboard data. |
| 177 | + * \param cleanup a function Pointer to the function that cleans up the |
| 178 | + * clipboard data. |
| 179 | + * \param userdata an opaque Pointer that will be forwarded to the callbacks. |
| 180 | + * \param mime_types a list of mime-types that are being offered. |
| 181 | + * \param num_mime_types the number of mime-types in the mime_types list. |
| 182 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 183 | + * information. |
| 184 | + * |
| 185 | + * \threadsafety You may only call this function from the main thread. |
| 186 | + * |
| 187 | + * \since This function is available since SDL 3.1.3. |
| 188 | + * |
| 189 | + * \sa SDL_ClearClipboardData |
| 190 | + * \sa SDL_GetClipboardData |
| 191 | + * \sa SDL_HasClipboardData |
| 192 | + } |
| 193 | +function SDL_SetClipboardData(callback: TSDL_ClipboardDataCallback; cleanup: TSDL_ClipboardCleanupCallback; userdata: Pointer; mime_types: PPAnsiChar; num_mime_types: size_t): cbool; cdecl; |
| 194 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetClipboardData' {$ENDIF} {$ENDIF}; |
| 195 | + |
| 196 | +{* |
| 197 | + * Clear the clipboard data. |
| 198 | + * |
| 199 | + * \returns true on success or false on failure; call SDL_GetError() for more |
| 200 | + * information. |
| 201 | + * |
| 202 | + * \threadsafety You may only call this function from the main thread. |
| 203 | + * |
| 204 | + * \since This function is available since SDL 3.1.3. |
| 205 | + * |
| 206 | + * \sa SDL_SetClipboardData |
| 207 | + } |
| 208 | +function SDL_ClearClipboardData: cbool; cdecl; |
| 209 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ClearClipboardData' {$ENDIF} {$ENDIF}; |
| 210 | + |
| 211 | +{* |
| 212 | + * Get the data from clipboard for a given mime type. |
| 213 | + * |
| 214 | + * The size of text data does not include the terminator, but the text is |
| 215 | + * guaranteed to be null terminated. |
| 216 | + * |
| 217 | + * \param mime_type the mime type to read from the clipboard. |
| 218 | + * \param size a Pointer filled in with the length of the returned data. |
| 219 | + * \returns the retrieved data buffer or nil on failure; call SDL_GetError() |
| 220 | + * for more information. This should be freed with SDL_free() when it |
| 221 | + * is no longer needed. |
| 222 | + * |
| 223 | + * \threadsafety You may only call this function from the main thread. |
| 224 | + * |
| 225 | + * \since This function is available since SDL 3.1.3. |
| 226 | + * |
| 227 | + * \sa SDL_HasClipboardData |
| 228 | + * \sa SDL_SetClipboardData |
| 229 | + } |
| 230 | +function SDL_GetClipboardData(mime_type: PAnsiChar; size: psize_t): Pointer; cdecl; |
| 231 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetClipboardData' {$ENDIF} {$ENDIF}; |
| 232 | + |
| 233 | +{* |
| 234 | + * Query whether there is data in the clipboard for the provided mime type. |
| 235 | + * |
| 236 | + * \param mime_type the mime type to check for data for. |
| 237 | + * \returns true if there exists data in clipboard for the provided mime type, |
| 238 | + * false if it does not. |
| 239 | + * |
| 240 | + * \threadsafety You may only call this function from the main thread. |
| 241 | + * |
| 242 | + * \since This function is available since SDL 3.1.3. |
| 243 | + * |
| 244 | + * \sa SDL_SetClipboardData |
| 245 | + * \sa SDL_GetClipboardData |
| 246 | + } |
| 247 | +function SDL_HasClipboardData(mime_type: PAnsiChar): cbool; cdecl; |
| 248 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasClipboardData' {$ENDIF} {$ENDIF}; |
| 249 | + |
| 250 | +{* |
| 251 | + * Retrieve the list of mime types available in the clipboard. |
| 252 | + * |
| 253 | + * \param num_mime_types a Pointer filled with the number of mime types, may |
| 254 | + * be nil. |
| 255 | + * \returns a null terminated array of strings with mime types, or nil on |
| 256 | + * failure; call SDL_GetError() for more information. This should be |
| 257 | + * freed with SDL_free() when it is no longer needed. |
| 258 | + * |
| 259 | + * \threadsafety You may only call this function from the main thread. |
| 260 | + * |
| 261 | + * \since This function is available since SDL 3.1.3. |
| 262 | + * |
| 263 | + * \sa SDL_SetClipboardData |
| 264 | + } |
| 265 | +function SDL_GetClipboardMimeTypes(num_mime_types: psize_t):PPAnsiChar; cdecl; |
| 266 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetClipboardMimeTypes' {$ENDIF} {$ENDIF}; |
| 267 | + |
0 commit comments