SDL_dialog.h 11 KB

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