SDL_dialog.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. * # CategoryDialog
  20. *
  21. * File dialog support.
  22. */
  23. #ifndef SDL_dialog_h_
  24. #define SDL_dialog_h_
  25. #include <SDL3/SDL_error.h>
  26. #include <SDL3/SDL_video.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. /**
  33. * An entry for filters for file dialogs.
  34. *
  35. * `name` is a user-readable label for the filter (for example, "Office
  36. * document").
  37. *
  38. * `pattern` is a semicolon-separated list of file extensions (for example,
  39. * "doc;docx"). File extensions may only contain alphanumeric characters,
  40. * hyphens, underscores and periods. Alternatively, the whole string can be a
  41. * single asterisk ("*"), which serves as an "All files" filter.
  42. *
  43. * \since This struct is available since SDL 3.0.0.
  44. *
  45. * \sa SDL_DialogFileCallback
  46. * \sa SDL_ShowOpenFileDialog
  47. * \sa SDL_ShowSaveFileDialog
  48. * \sa SDL_ShowOpenFolderDialog
  49. */
  50. typedef struct SDL_DialogFileFilter
  51. {
  52. const char *name;
  53. const char *pattern;
  54. } SDL_DialogFileFilter;
  55. /**
  56. * Callback used by file dialog functions.
  57. *
  58. * The specific usage is described in each function.
  59. *
  60. * If `filelist` is:
  61. *
  62. * - NULL, an error occured. Details can be obtained with SDL_GetError().
  63. * - A pointer to NULL, the user either didn't choose any file or canceled the
  64. * dialog.
  65. * - A pointer to non-`NULL`, the user chose one or more files. The argument
  66. * is a null-terminated list of pointers to C strings, each containing a
  67. * path.
  68. *
  69. * The filelist argument does not need to be freed; it will automatically be
  70. * freed when the callback returns.
  71. *
  72. * The filter argument is the index of the filter that was selected, or one
  73. * more than the size of the list (therefore the index of the terminating NULL
  74. * entry) if no filter was selected, or -1 if the platform or method doesn't
  75. * support fetching the selected filter.
  76. *
  77. * \param userdata An app-provided pointer, for the callback's use.
  78. * \param filelist The file(s) chosen by the user.
  79. * \param filter Index of the selected filter.
  80. *
  81. * \since This datatype is available since SDL 3.0.0.
  82. *
  83. * \sa SDL_DialogFileFilter
  84. * \sa SDL_ShowOpenFileDialog
  85. * \sa SDL_ShowSaveFileDialog
  86. * \sa SDL_ShowOpenFolderDialog
  87. */
  88. typedef void(SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);
  89. /**
  90. * Displays a dialog that lets the user select a file on their filesystem.
  91. *
  92. * This function should only be invoked from the main thread.
  93. *
  94. * This is an asynchronous function; it will return immediately, and the
  95. * result will be passed to the callback.
  96. *
  97. * The callback will be invoked with a null-terminated list of files the user
  98. * chose. The list will be empty if the user canceled the dialog, and it will
  99. * be NULL if an error occured.
  100. *
  101. * Note that the callback may be called from a different thread than the one
  102. * the function was invoked on.
  103. *
  104. * Depending on the platform, the user may be allowed to input paths that
  105. * don't yet exist.
  106. *
  107. * \param callback An SDL_DialogFileCallback to be invoked when the user
  108. * selects a file and accepts, or cancels the dialog, or an
  109. * error occurs. The first argument is a null-terminated list
  110. * of C strings, representing the paths chosen by the user.
  111. * The list will be empty if the user canceled the dialog, and
  112. * it will be NULL if an error occured. If an error occured,
  113. * it can be fetched with SDL_GetError(). The second argument
  114. * is the userdata pointer passed to the function. The third
  115. * argument is the index of the filter selected by the user,
  116. * or one past the index of the last filter (therefore the
  117. * index of the terminating NULL filter) if no filter was
  118. * chosen, or -1 if the platform does not support detecting
  119. * the selected filter.
  120. * \param userdata An optional pointer to pass extra data to the callback when
  121. * it will be invoked.
  122. * \param window The window that the dialog should be modal for. May be NULL.
  123. * Not all platforms support this option.
  124. * \param filters A null-terminated list of SDL_DialogFileFilter's. May be
  125. * NULL. Not all platforms support this option, and platforms
  126. * that do support it may allow the user to ignore the filters.
  127. * \param default_location The default folder or file to start the dialog at.
  128. * May be NULL. Not all platforms support this option.
  129. * \param allow_many If non-zero, the user will be allowed to select multiple
  130. * entries. Not all platforms support this option.
  131. *
  132. * \since This function is available since SDL 3.0.0.
  133. *
  134. * \sa SDL_DialogFileCallback
  135. * \sa SDL_DialogFileFilter
  136. * \sa SDL_ShowSaveFileDialog
  137. * \sa SDL_ShowOpenFolderDialog
  138. */
  139. extern DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, const char *default_location, SDL_bool allow_many);
  140. /**
  141. * Displays a dialog that lets the user choose a new or existing file on their
  142. * filesystem.
  143. *
  144. * This function should only be invoked from the main thread.
  145. *
  146. * This is an asynchronous function; it will return immediately, and the
  147. * result will be passed to the callback.
  148. *
  149. * The callback will be invoked with a null-terminated list of files the user
  150. * chose. The list will be empty if the user canceled the dialog, and it will
  151. * be NULL if an error occured.
  152. *
  153. * Note that the callback may be called from a different thread than the one
  154. * the function was invoked on.
  155. *
  156. * The chosen file may or may not already exist.
  157. *
  158. * \param callback An SDL_DialogFileCallback to be invoked when the user
  159. * selects a file and accepts, or cancels the dialog, or an
  160. * error occurs. The first argument is a null-terminated list
  161. * of C strings, representing the paths chosen by the user.
  162. * The list will be empty if the user canceled the dialog, and
  163. * it will be NULL if an error occured. If an error occured,
  164. * it can be fetched with SDL_GetError(). The second argument
  165. * is the userdata pointer passed to the function. The third
  166. * argument is the index of the filter selected by the user,
  167. * or one past the index of the last filter (therefore the
  168. * index of the terminating NULL filter) if no filter was
  169. * chosen, or -1 if the platform does not support detecting
  170. * the selected filter.
  171. * \param userdata An optional pointer to pass extra data to the callback when
  172. * it will be invoked.
  173. * \param window The window that the dialog should be modal for. May be NULL.
  174. * Not all platforms support this option.
  175. * \param filters A null-terminated list of SDL_DialogFileFilter's. May be
  176. * NULL. Not all platforms support this option, and platforms
  177. * that do support it may allow the user to ignore the filters.
  178. * \param default_location The default folder or file to start the dialog at.
  179. * May be NULL. Not all platforms support this option.
  180. *
  181. * \since This function is available since SDL 3.0.0.
  182. *
  183. * \sa SDL_DialogFileCallback
  184. * \sa SDL_DialogFileFilter
  185. * \sa SDL_ShowOpenFileDialog
  186. * \sa SDL_ShowOpenFolderDialog
  187. */
  188. extern DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, const char *default_location);
  189. /**
  190. * Displays a dialog that lets the user select a folder on their filesystem.
  191. *
  192. * This function should only be invoked from the main thread.
  193. *
  194. * This is an asynchronous function; it will return immediately, and the
  195. * result will be passed to the callback.
  196. *
  197. * The callback will be invoked with a null-terminated list of files the user
  198. * chose. The list will be empty if the user canceled the dialog, and it will
  199. * be NULL if an error occured.
  200. *
  201. * Note that the callback may be called from a different thread than the one
  202. * the function was invoked on.
  203. *
  204. * Depending on the platform, the user may be allowed to input paths that
  205. * don't yet exist.
  206. *
  207. * \param callback An SDL_DialogFileCallback to be invoked when the user
  208. * selects a file and accepts, or cancels the dialog, or an
  209. * error occurs. The first argument is a null-terminated list
  210. * of C strings, representing the paths chosen by the user.
  211. * The list will be empty if the user canceled the dialog, and
  212. * it will be NULL if an error occured. If an error occured,
  213. * it can be fetched with SDL_GetError(). The second argument
  214. * is the userdata pointer passed to the function. The third
  215. * argument is always -1 for SDL_ShowOpenFolderDialog.
  216. * \param userdata An optional pointer to pass extra data to the callback when
  217. * it will be invoked.
  218. * \param window The window that the dialog should be modal for. May be NULL.
  219. * Not all platforms support this option.
  220. * \param default_location The default folder or file to start the dialog at.
  221. * May be NULL. Not all platforms support this option.
  222. * \param allow_many If non-zero, the user will be allowed to select multiple
  223. * entries. Not all platforms support this option.
  224. *
  225. * \since This function is available since SDL 3.0.0.
  226. *
  227. * \sa SDL_DialogFileCallback
  228. * \sa SDL_ShowOpenFileDialog
  229. * \sa SDL_ShowSaveFileDialog
  230. */
  231. extern DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, SDL_bool allow_many);
  232. /* Ends C function definitions when using C++ */
  233. #ifdef __cplusplus
  234. }
  235. #endif
  236. #include <SDL3/SDL_close_code.h>
  237. #endif /* SDL_joystick_h_ */