SDL_dialog.h 9.5 KB

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