SDL_dialog.h 9.3 KB

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