FileBrowserDialogImpl.hpp (4783B)
1 /* 2 * DISTRHO Plugin Framework (DPF) 3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any purpose with 6 * or without fee is hereby granted, provided that the above copyright notice and this 7 * permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD 10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN 11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #if !defined(DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED) && !defined(DGL_FILE_BROWSER_DIALOG_HPP_INCLUDED) 18 # error bad include 19 #endif 20 21 // -------------------------------------------------------------------------------------------------------------------- 22 // File Browser Dialog stuff 23 24 struct FileBrowserData; 25 typedef FileBrowserData* FileBrowserHandle; 26 27 // -------------------------------------------------------------------------------------------------------------------- 28 29 /** 30 File browser options, for customizing the file browser dialog.@n 31 By default the file browser dialog will be work as "open file" in the current working directory. 32 */ 33 struct FileBrowserOptions { 34 /** Whether we are saving, opening files otherwise (default) */ 35 bool saving; 36 37 /** Default filename when saving, required in some platforms (basename without path separators) */ 38 const char* defaultName; 39 40 /** Start directory, uses current working directory if null */ 41 const char* startDir; 42 43 /** File browser dialog window title, uses "FileBrowser" if null */ 44 const char* title; 45 46 /** Class name of the matching Application instance that controls this dialog */ 47 const char* className; 48 49 // TODO file filter 50 51 /** 52 File browser button state. 53 This allows to customize the behaviour of the file browse dialog buttons. 54 Note these are merely hints, not all systems support them. 55 */ 56 enum ButtonState { 57 kButtonInvisible, 58 kButtonVisibleUnchecked, 59 kButtonVisibleChecked, 60 }; 61 62 /** 63 File browser buttons. 64 */ 65 struct Buttons { 66 /** Whether to list all files vs only those with matching file extension */ 67 ButtonState listAllFiles; 68 /** Whether to show hidden files */ 69 ButtonState showHidden; 70 /** Whether to show list of places (bookmarks) */ 71 ButtonState showPlaces; 72 73 /** Constructor for default values */ 74 Buttons() 75 : listAllFiles(kButtonVisibleChecked), 76 showHidden(kButtonVisibleUnchecked), 77 showPlaces(kButtonVisibleChecked) {} 78 } buttons; 79 80 /** Constructor for default values */ 81 FileBrowserOptions() 82 : saving(false), 83 defaultName(nullptr), 84 startDir(nullptr), 85 title(nullptr), 86 className(nullptr), 87 buttons() {} 88 }; 89 90 // -------------------------------------------------------------------------------------------------------------------- 91 92 /** 93 Create a new file browser dialog. 94 95 @p isEmbed: Whether the window this dialog belongs to is an embed/child window (needed to close dialog on Windows) 96 @p windowId: The native window id to attach this dialog to as transient parent (X11 Window, HWND or NSView*) 97 @p scaleFactor: Scale factor to use (only used on X11) 98 @p options: Extra options, optional 99 By default the file browser dialog will work as "open file" in the current working directory. 100 */ 101 FileBrowserHandle fileBrowserCreate(bool isEmbed, 102 uintptr_t windowId, 103 double scaleFactor, 104 const FileBrowserOptions& options = FileBrowserOptions()); 105 106 /** 107 Idle the file browser dialog handle.@n 108 Returns true if dialog was closed (with or without a file selection), 109 in which case this idle function must not be called anymore for this handle. 110 You can then call fileBrowserGetPath to know the selected file (or null if cancelled). 111 */ 112 bool fileBrowserIdle(const FileBrowserHandle handle); 113 114 /** 115 Close and free the file browser dialog, handle must not be used afterwards. 116 */ 117 void fileBrowserClose(const FileBrowserHandle handle); 118 119 /** 120 Get the path chosen by the user or null.@n 121 Should only be called after fileBrowserIdle returns true. 122 */ 123 const char* fileBrowserGetPath(const FileBrowserHandle handle); 124 125 // --------------------------------------------------------------------------------------------------------------------