SDL_dialog.h 9.5 KB

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