SDL_dialog.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. #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 or if an error occured.
  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 The function to be invoked when the user selects a file and
  96. * accepts, or the user cancels the dialog, or an error
  97. * occurs. The first argument is a null-terminated list of C
  98. * strings, representing the paths chosen by the user. The
  99. * list will be empty if the user canceled the dialog, and it
  100. * will be NULL if an error occured. If an error occured, it
  101. * can be fetched with SDL_GetError(). The second argument is
  102. * the userdata pointer passed to the function.
  103. * \param userdata An optional pointer to pass extra data to the callback when
  104. * it will be invoked.
  105. * \param window The window that the dialog should be modal for. May be NULL.
  106. * Not all platforms support this option.
  107. * \param filters A null-terminated list of SDL_DialogFileFilter's. May be
  108. * NULL. Not all platforms support this option, and platforms
  109. * that do support it may allow the user to ignore the filters.
  110. * \param default_location The default folder or file to start the dialog at.
  111. * May be NULL. Not all platforms support this option.
  112. * \param allow_many If non-zero, the user will be allowed to select multiple
  113. * entries. Not all platforms support this option.
  114. *
  115. * \since This function is available since SDL 3.0.0.
  116. *
  117. * \sa SDL_ShowSaveFileDialog
  118. * \sa SDL_ShowOpenFolderDialog
  119. */
  120. 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);
  121. /**
  122. * Displays a dialog that lets the user choose a new or existing file on their
  123. * filesystem.
  124. *
  125. * This function should only be invoked from the main thread.
  126. *
  127. * This is an asynchronous function; it will return immediately, and the
  128. * result will be passed to the callback.
  129. *
  130. * The callback will be invoked with a null-terminated list of files the user
  131. * chose. The list will be empty if the user canceled the dialog, and it will
  132. * be NULL if an error occured.
  133. *
  134. * Note that the callback may be called from a different thread than the one
  135. * the function was invoked on.
  136. *
  137. * The chosen file may or may not already exist.
  138. *
  139. * \param callback The function to be invoked when the user selects a file and
  140. * accepts, or the user cancels the dialog, or an error
  141. * occurs. The first argument is a null-terminated list of C
  142. * strings, representing the paths chosen by the user. The
  143. * list will be empty if the user canceled the dialog, and it
  144. * will be NULL if an error occured. If an error occured, it
  145. * can be fetched with SDL_GetError(). The second argument is
  146. * the userdata pointer passed to the function.
  147. * \param userdata An optional pointer to pass extra data to the callback when
  148. * it will be invoked.
  149. * \param window The window that the dialog should be modal for. May be NULL.
  150. * Not all platforms support this option.
  151. * \param filters A null-terminated list of SDL_DialogFileFilter's. May be
  152. * NULL. Not all platforms support this option, and platforms
  153. * that do support it may allow the user to ignore the filters.
  154. * \param default_location The default folder or file to start the dialog at.
  155. * May be NULL. Not all platforms support this option.
  156. *
  157. * \since This function is available since SDL 3.0.0.
  158. *
  159. * \sa SDL_ShowOpenFileDialog
  160. */
  161. extern DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, const char *default_location);
  162. /**
  163. * Displays a dialog that lets the user select a folder on their filesystem.
  164. *
  165. * This function should only be invoked from the main thread.
  166. *
  167. * This is an asynchronous function; it will return immediately, and the
  168. * result will be passed to the callback.
  169. *
  170. * The callback will be invoked with a null-terminated list of files the user
  171. * chose. The list will be empty if the user canceled the dialog, and it will
  172. * be NULL if an error occured.
  173. *
  174. * Note that the callback may be called from a different thread than the one
  175. * the function was invoked on.
  176. *
  177. * Depending on the platform, the user may be allowed to input paths that
  178. * don't yet exist.
  179. *
  180. * \param callback The function to be invoked when the user selects a folder
  181. * and accepts, or the user cancels the dialog, or an error
  182. * occurs. The first argument is a null-terminated list of C
  183. * strings, representing the paths chosen by the user. The
  184. * list will be empty if the user canceled the dialog, and it
  185. * will be NULL if an error occured. If an error occured, it
  186. * can be fetched with SDL_GetError(). The second argument is
  187. * the userdata pointer passed to the function.
  188. * \param userdata An optional pointer to pass extra data to the callback when
  189. * it will be invoked.
  190. * \param window The window that the dialog should be modal for. May be NULL.
  191. * Not all platforms support this option.
  192. * \param default_location The default folder or file to start the dialog at.
  193. * May be NULL. Not all platforms support this option.
  194. * \param allow_many If non-zero, the user will be allowed to select multiple
  195. * entries. Not all platforms support this option.
  196. *
  197. * \since This function is available since SDL 3.0.0.
  198. *
  199. * \sa SDL_ShowOpenFileDialog
  200. */
  201. extern DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, SDL_bool allow_many);
  202. /* Ends C function definitions when using C++ */
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #include <SDL3/SDL_close_code.h>
  207. #endif /* SDL_joystick_h_ */