Path: blob/master/thirdparty/sdl/include/SDL3/SDL_dialog.h
9912 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* # CategoryDialog23*24* File dialog support.25*26* SDL offers file dialogs, to let users select files with native GUI27* interfaces. There are "open" dialogs, "save" dialogs, and folder selection28* dialogs. The app can control some details, such as filtering to specific29* files, or whether multiple files can be selected by the user.30*31* Note that launching a file dialog is a non-blocking operation; control32* returns to the app immediately, and a callback is called later (possibly in33* another thread) when the user makes a choice.34*/3536#ifndef SDL_dialog_h_37#define SDL_dialog_h_3839#include <SDL3/SDL_stdinc.h>40#include <SDL3/SDL_error.h>41#include <SDL3/SDL_properties.h>42#include <SDL3/SDL_video.h>4344#include <SDL3/SDL_begin_code.h>45/* Set up for C function definitions, even when using C++ */46#ifdef __cplusplus47extern "C" {48#endif4950/**51* An entry for filters for file dialogs.52*53* `name` is a user-readable label for the filter (for example, "Office54* document").55*56* `pattern` is a semicolon-separated list of file extensions (for example,57* "doc;docx"). File extensions may only contain alphanumeric characters,58* hyphens, underscores and periods. Alternatively, the whole string can be a59* single asterisk ("*"), which serves as an "All files" filter.60*61* \since This struct is available since SDL 3.2.0.62*63* \sa SDL_DialogFileCallback64* \sa SDL_ShowOpenFileDialog65* \sa SDL_ShowSaveFileDialog66* \sa SDL_ShowOpenFolderDialog67* \sa SDL_ShowFileDialogWithProperties68*/69typedef struct SDL_DialogFileFilter70{71const char *name;72const char *pattern;73} SDL_DialogFileFilter;7475/**76* Callback used by file dialog functions.77*78* The specific usage is described in each function.79*80* If `filelist` is:81*82* - NULL, an error occurred. Details can be obtained with SDL_GetError().83* - A pointer to NULL, the user either didn't choose any file or canceled the84* dialog.85* - A pointer to non-`NULL`, the user chose one or more files. The argument86* is a null-terminated array of pointers to UTF-8 encoded strings, each87* containing a path.88*89* The filelist argument should not be freed; it will automatically be freed90* when the callback returns.91*92* The filter argument is the index of the filter that was selected, or -1 if93* no filter was selected or if the platform or method doesn't support94* fetching the selected filter.95*96* In Android, the `filelist` are `content://` URIs. They should be opened97* using SDL_IOFromFile() with appropriate modes. This applies both to open98* and save file dialog.99*100* \param userdata an app-provided pointer, for the callback's use.101* \param filelist the file(s) chosen by the user.102* \param filter index of the selected filter.103*104* \since This datatype is available since SDL 3.2.0.105*106* \sa SDL_DialogFileFilter107* \sa SDL_ShowOpenFileDialog108* \sa SDL_ShowSaveFileDialog109* \sa SDL_ShowOpenFolderDialog110* \sa SDL_ShowFileDialogWithProperties111*/112typedef void (SDLCALL *SDL_DialogFileCallback)(void *userdata, const char * const *filelist, int filter);113114/**115* Displays a dialog that lets the user select a file on their filesystem.116*117* This is an asynchronous function; it will return immediately, and the118* result will be passed to the callback.119*120* The callback will be invoked with a null-terminated list of files the user121* chose. The list will be empty if the user canceled the dialog, and it will122* be NULL if an error occurred.123*124* Note that the callback may be called from a different thread than the one125* the function was invoked on.126*127* Depending on the platform, the user may be allowed to input paths that128* don't yet exist.129*130* On Linux, dialogs may require XDG Portals, which requires DBus, which131* requires an event-handling loop. Apps that do not use SDL to handle events132* should add a call to SDL_PumpEvents in their main loop.133*134* \param callback a function pointer to be invoked when the user selects a135* file and accepts, or cancels the dialog, or an error136* occurs.137* \param userdata an optional pointer to pass extra data to the callback when138* it will be invoked.139* \param window the window that the dialog should be modal for, may be NULL.140* Not all platforms support this option.141* \param filters a list of filters, may be NULL. Not all platforms support142* this option, and platforms that do support it may allow the143* user to ignore the filters. If non-NULL, it must remain144* valid at least until the callback is invoked.145* \param nfilters the number of filters. Ignored if filters is NULL.146* \param default_location the default folder or file to start the dialog at,147* may be NULL. Not all platforms support this option.148* \param allow_many if non-zero, the user will be allowed to select multiple149* entries. Not all platforms support this option.150*151* \threadsafety This function should be called only from the main thread. The152* callback may be invoked from the same thread or from a153* different one, depending on the OS's constraints.154*155* \since This function is available since SDL 3.2.0.156*157* \sa SDL_DialogFileCallback158* \sa SDL_DialogFileFilter159* \sa SDL_ShowSaveFileDialog160* \sa SDL_ShowOpenFolderDialog161* \sa SDL_ShowFileDialogWithProperties162*/163extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location, bool allow_many);164165/**166* Displays a dialog that lets the user choose a new or existing file on their167* filesystem.168*169* This is an asynchronous function; it will return immediately, and the170* result will be passed to the callback.171*172* The callback will be invoked with a null-terminated list of files the user173* chose. The list will be empty if the user canceled the dialog, and it will174* be NULL if an error occurred.175*176* Note that the callback may be called from a different thread than the one177* the function was invoked on.178*179* The chosen file may or may not already exist.180*181* On Linux, dialogs may require XDG Portals, which requires DBus, which182* requires an event-handling loop. Apps that do not use SDL to handle events183* should add a call to SDL_PumpEvents in their main loop.184*185* \param callback a function pointer to be invoked when the user selects a186* file and accepts, or cancels the dialog, or an error187* occurs.188* \param userdata an optional pointer to pass extra data to the callback when189* 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 filters a list of filters, may be NULL. Not all platforms support193* this option, and platforms that do support it may allow the194* user to ignore the filters. If non-NULL, it must remain195* valid at least until the callback is invoked.196* \param nfilters the number of filters. Ignored if filters is NULL.197* \param default_location the default folder or file to start the dialog at,198* may be NULL. Not all platforms support this option.199*200* \threadsafety This function should be called only from the main thread. The201* callback may be invoked from the same thread or from a202* different one, depending on the OS's constraints.203*204* \since This function is available since SDL 3.2.0.205*206* \sa SDL_DialogFileCallback207* \sa SDL_DialogFileFilter208* \sa SDL_ShowOpenFileDialog209* \sa SDL_ShowOpenFolderDialog210* \sa SDL_ShowFileDialogWithProperties211*/212extern SDL_DECLSPEC void SDLCALL SDL_ShowSaveFileDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const SDL_DialogFileFilter *filters, int nfilters, const char *default_location);213214/**215* Displays a dialog that lets the user select a folder on their filesystem.216*217* This is an asynchronous function; it will return immediately, and the218* result will be passed to the callback.219*220* The callback will be invoked with a null-terminated list of files the user221* chose. The list will be empty if the user canceled the dialog, and it will222* be NULL if an error occurred.223*224* Note that the callback may be called from a different thread than the one225* the function was invoked on.226*227* Depending on the platform, the user may be allowed to input paths that228* don't yet exist.229*230* On Linux, dialogs may require XDG Portals, which requires DBus, which231* requires an event-handling loop. Apps that do not use SDL to handle events232* should add a call to SDL_PumpEvents in their main loop.233*234* \param callback a function pointer to be invoked when the user selects a235* file and accepts, or cancels the dialog, or an error236* occurs.237* \param userdata an optional pointer to pass extra data to the callback when238* it will be invoked.239* \param window the window that the dialog should be modal for, may be NULL.240* Not all platforms support this option.241* \param default_location the default folder or file to start the dialog at,242* may be NULL. Not all platforms support this option.243* \param allow_many if non-zero, the user will be allowed to select multiple244* entries. Not all platforms support this option.245*246* \threadsafety This function should be called only from the main thread. The247* callback may be invoked from the same thread or from a248* different one, depending on the OS's constraints.249*250* \since This function is available since SDL 3.2.0.251*252* \sa SDL_DialogFileCallback253* \sa SDL_ShowOpenFileDialog254* \sa SDL_ShowSaveFileDialog255* \sa SDL_ShowFileDialogWithProperties256*/257extern SDL_DECLSPEC void SDLCALL SDL_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void *userdata, SDL_Window *window, const char *default_location, bool allow_many);258259/**260* Various types of file dialogs.261*262* This is used by SDL_ShowFileDialogWithProperties() to decide what kind of263* dialog to present to the user.264*265* \since This enum is available since SDL 3.2.0.266*267* \sa SDL_ShowFileDialogWithProperties268*/269typedef enum SDL_FileDialogType270{271SDL_FILEDIALOG_OPENFILE,272SDL_FILEDIALOG_SAVEFILE,273SDL_FILEDIALOG_OPENFOLDER274} SDL_FileDialogType;275276/**277* Create and launch a file dialog with the specified properties.278*279* These are the supported properties:280*281* - `SDL_PROP_FILE_DIALOG_FILTERS_POINTER`: a pointer to a list of282* SDL_DialogFileFilter structs, which will be used as filters for283* file-based selections. Ignored if the dialog is an "Open Folder" dialog.284* If non-NULL, the array of filters must remain valid at least until the285* callback is invoked.286* - `SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER`: the number of filters in the287* array of filters, if it exists.288* - `SDL_PROP_FILE_DIALOG_WINDOW_POINTER`: the window that the dialog should289* be modal for.290* - `SDL_PROP_FILE_DIALOG_LOCATION_STRING`: the default folder or file to291* start the dialog at.292* - `SDL_PROP_FILE_DIALOG_MANY_BOOLEAN`: true to allow the user to select293* more than one entry.294* - `SDL_PROP_FILE_DIALOG_TITLE_STRING`: the title for the dialog.295* - `SDL_PROP_FILE_DIALOG_ACCEPT_STRING`: the label that the accept button296* should have.297* - `SDL_PROP_FILE_DIALOG_CANCEL_STRING`: the label that the cancel button298* should have.299*300* Note that each platform may or may not support any of the properties.301*302* \param type the type of file dialog.303* \param callback a function pointer to be invoked when the user selects a304* file and accepts, or cancels the dialog, or an error305* occurs.306* \param userdata an optional pointer to pass extra data to the callback when307* it will be invoked.308* \param props the properties to use.309*310* \threadsafety This function should be called only from the main thread. The311* callback may be invoked from the same thread or from a312* different one, depending on the OS's constraints.313*314* \since This function is available since SDL 3.2.0.315*316* \sa SDL_FileDialogType317* \sa SDL_DialogFileCallback318* \sa SDL_DialogFileFilter319* \sa SDL_ShowOpenFileDialog320* \sa SDL_ShowSaveFileDialog321* \sa SDL_ShowOpenFolderDialog322*/323extern SDL_DECLSPEC void SDLCALL SDL_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props);324325#define SDL_PROP_FILE_DIALOG_FILTERS_POINTER "SDL.filedialog.filters"326#define SDL_PROP_FILE_DIALOG_NFILTERS_NUMBER "SDL.filedialog.nfilters"327#define SDL_PROP_FILE_DIALOG_WINDOW_POINTER "SDL.filedialog.window"328#define SDL_PROP_FILE_DIALOG_LOCATION_STRING "SDL.filedialog.location"329#define SDL_PROP_FILE_DIALOG_MANY_BOOLEAN "SDL.filedialog.many"330#define SDL_PROP_FILE_DIALOG_TITLE_STRING "SDL.filedialog.title"331#define SDL_PROP_FILE_DIALOG_ACCEPT_STRING "SDL.filedialog.accept"332#define SDL_PROP_FILE_DIALOG_CANCEL_STRING "SDL.filedialog.cancel"333334/* Ends C function definitions when using C++ */335#ifdef __cplusplus336}337#endif338#include <SDL3/SDL_close_code.h>339340#endif /* SDL_dialog_h_ */341342343