SDL_dialog.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 -1 if
  73. * no filter was selected or if the platform or method doesn't support
  74. * fetching the selected filter.
  75. *
  76. * \param userdata an app-provided pointer, for the callback's use.
  77. * \param filelist the file(s) chosen by the user.
  78. * \param filter index of the selected filter.
  79. *
  80. * \since This datatype is available since SDL 3.0.0.
  81. *
  82. * \sa SDL_DialogFileFilter
  83. * \sa SDL_ShowOpenFileDialog
  84. * \sa SDL_ShowSaveFileDialog
  85. * \sa SDL_ShowOpenFolderDialog
  86. */
  87. typedef void(SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);
  88. /**
  89. * Displays a dialog that lets the user select a file on their filesystem.
  90. *
  91. * This function should only be invoked from the main thread.
  92. *
  93. * This is an asynchronous function; it will return immediately, and the
  94. * result will be passed to the callback.
  95. *
  96. * The callback will be invoked with a null-terminated list of files the user
  97. * chose. The list will be empty if the user canceled the dialog, and it will
  98. * be NULL if an error occured.
  99. *
  100. * Note that the callback may be called from a different thread than the one
  101. * the function was invoked on.
  102. *
  103. * Depending on the platform, the user may be allowed to input paths that
  104. * don't yet exist.
  105. *
  106. * On Linux, dialogs may require XDG Portals, which requires DBus, which
  107. * requires an event-handling loop. Apps that do not use SDL to handle events
  108. * should add a call to SDL_PumpEvents in their main loop.
  109. *
  110. * \param callback an SDL_DialogFileCallback to be invoked when the user
  111. * selects a file and accepts, or cancels the dialog, or an
  112. * error occurs. The first argument is a null-terminated list
  113. * of C strings, representing the paths chosen by the user.
  114. * The list will be empty if the user canceled the dialog, and
  115. * it will be NULL if an error occured. If an error occured,
  116. * it can be fetched with SDL_GetError(). The second argument
  117. * is the userdata pointer passed to the function. The third
  118. * argument is the index of the filter selected by the user,
  119. * or one past the index of the last filter (therefore the
  120. * index of the terminating NULL filter) if no filter was
  121. * chosen, or -1 if the platform does not support detecting
  122. * the selected filter.
  123. * \param userdata an optional pointer to pass extra data to the callback when
  124. * it will be invoked.
  125. * \param window the window that the dialog should be modal for. May be NULL.
  126. * Not all platforms support this option.
  127. * \param filters a list of SDL_DialogFileFilter's. May be NULL. Not all
  128. * platforms support this option, and platforms that do support
  129. * it may allow the user to ignore the filters.
  130. * \param nfilters the number of filters. Ignored if filters is NULL.
  131. * \param default_location the default folder or file to start the dialog at.
  132. * May be NULL. Not all platforms support this option.
  133. * \param allow_many if non-zero, the user will be allowed to select multiple
  134. * entries. Not all platforms support this option.
  135. *
  136. * \since This function is available since SDL 3.0.0.
  137. *
  138. * \sa SDL_DialogFileCallback
  139. * \sa SDL_DialogFileFilter
  140. * \sa SDL_ShowSaveFileDialog
  141. * \sa SDL_ShowOpenFolderDialog
  142. */
  143. extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, SDL_bool allow_many);
  144. /**
  145. * Displays a dialog that lets the user choose a new or existing file on their
  146. * filesystem.
  147. *
  148. * This function should only be invoked from the main thread.
  149. *
  150. * This is an asynchronous function; it will return immediately, and the
  151. * result will be passed to the callback.
  152. *
  153. * The callback will be invoked with a null-terminated list of files the user
  154. * chose. The list will be empty if the user canceled the dialog, and it will
  155. * be NULL if an error occured.
  156. *
  157. * Note that the callback may be called from a different thread than the one
  158. * the function was invoked on.
  159. *
  160. * The chosen file may or may not already exist.
  161. *
  162. * On Linux, dialogs may require XDG Portals, which requires DBus, which
  163. * requires an event-handling loop. Apps that do not use SDL to handle events
  164. * should add a call to SDL_PumpEvents in their main loop.
  165. *
  166. * \param callback an SDL_DialogFileCallback to be invoked when the user
  167. * selects a file and accepts, or cancels the dialog, or an
  168. * error occurs. The first argument is a null-terminated list
  169. * of C strings, representing the paths chosen by the user.
  170. * The list will be empty if the user canceled the dialog, and
  171. * it will be NULL if an error occured. If an error occured,
  172. * it can be fetched with SDL_GetError(). The second argument
  173. * is the userdata pointer passed to the function. The third
  174. * argument is the index of the filter selected by the user,
  175. * or one past the index of the last filter (therefore the
  176. * index of the terminating NULL filter) if no filter was
  177. * chosen, or -1 if the platform does not support detecting
  178. * the selected filter.
  179. * \param userdata an optional pointer to pass extra data to the callback when
  180. * it will be invoked.
  181. * \param window the window that the dialog should be modal for. May be NULL.
  182. * Not all platforms support this option.
  183. * \param filters a list of SDL_DialogFileFilter's. May be NULL. Not all
  184. * platforms support this option, and platforms that do support
  185. * it may allow the user to ignore the filters.
  186. * \param nfilters the number of filters. Ignored if filters is NULL.
  187. * \param default_location the default folder or file to start the dialog at.
  188. * May be NULL. Not all platforms support this option.
  189. *
  190. * \since This function is available since SDL 3.0.0.
  191. *
  192. * \sa SDL_DialogFileCallback
  193. * \sa SDL_DialogFileFilter
  194. * \sa SDL_ShowOpenFileDialog
  195. * \sa SDL_ShowOpenFolderDialog
  196. */
  197. extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location);
  198. /**
  199. * Displays a dialog that lets the user select a folder on their filesystem.
  200. *
  201. * This function should only be invoked from the main thread.
  202. *
  203. * This is an asynchronous function; it will return immediately, and the
  204. * result will be passed to the callback.
  205. *
  206. * The callback will be invoked with a null-terminated list of files the user
  207. * chose. The list will be empty if the user canceled the dialog, and it will
  208. * be NULL if an error occured.
  209. *
  210. * Note that the callback may be called from a different thread than the one
  211. * the function was invoked on.
  212. *
  213. * Depending on the platform, the user may be allowed to input paths that
  214. * don't yet exist.
  215. *
  216. * On Linux, dialogs may require XDG Portals, which requires DBus, which
  217. * requires an event-handling loop. Apps that do not use SDL to handle events
  218. * should add a call to SDL_PumpEvents in their main loop.
  219. *
  220. * \param callback an SDL_DialogFileCallback to be invoked when the user
  221. * selects a file and accepts, or cancels the dialog, or an
  222. * error occurs. The first argument is a null-terminated list
  223. * of C strings, representing the paths chosen by the user.
  224. * The list will be empty if the user canceled the dialog, and
  225. * it will be NULL if an error occured. If an error occured,
  226. * it can be fetched with SDL_GetError(). The second argument
  227. * is the userdata pointer passed to the function. The third
  228. * argument is always -1 for SDL_ShowOpenFolderDialog.
  229. * \param userdata an optional pointer to pass extra data to the callback when
  230. * it will be invoked.
  231. * \param window the window that the dialog should be modal for. May be NULL.
  232. * Not all platforms support this option.
  233. * \param default_location the default folder or file to start the dialog at.
  234. * May be NULL. Not all platforms support this option.
  235. * \param allow_many if non-zero, the user will be allowed to select multiple
  236. * entries. Not all platforms support this option.
  237. *
  238. * \since This function is available since SDL 3.0.0.
  239. *
  240. * \sa SDL_DialogFileCallback
  241. * \sa SDL_ShowOpenFileDialog
  242. * \sa SDL_ShowSaveFileDialog
  243. */
  244. extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, SDL_bool allow_many);
  245. /* Ends C function definitions when using C++ */
  246. #ifdef __cplusplus
  247. }
  248. #endif
  249. #include <SDL3/SDL_close_code.h>
  250. #endif /* SDL_joystick_h_ */