SDL_dialog.h 11 KB

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