SDL_dialog.h 9.3 KB

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