DISTRHO Plugin Framework
FileBrowserDialogImpl.hpp
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;
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 */
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  // TODO file filter
47 
48  /**
49  File browser button state.
50  This allows to customize the behaviour of the file browse dialog buttons.
51  Note these are merely hints, not all systems support them.
52  */
53  enum ButtonState {
54  kButtonInvisible,
55  kButtonVisibleUnchecked,
56  kButtonVisibleChecked,
57  };
58 
59  /**
60  File browser buttons.
61  */
62  struct Buttons {
63  /** Whether to list all files vs only those with matching file extension */
65  /** Whether to show hidden files */
67  /** Whether to show list of places (bookmarks) */
69 
70  /** Constructor for default values */
72  : listAllFiles(kButtonVisibleChecked),
73  showHidden(kButtonVisibleUnchecked),
74  showPlaces(kButtonVisibleChecked) {}
75  } buttons;
76 
77  /** Constructor for default values */
79  : saving(false),
80  defaultName(nullptr),
81  startDir(nullptr),
82  title(nullptr),
83  buttons() {}
84 };
85 
86 // --------------------------------------------------------------------------------------------------------------------
87 
88 /**
89  Create a new file browser dialog.
90 
91  @p isEmbed: Whether the window this dialog belongs to is an embed/child window (needed to close dialog on Windows)
92  @p windowId: The native window id to attach this dialog to as transient parent (X11 Window, HWND or NSView*)
93  @p scaleFactor: Scale factor to use (only used on X11)
94  @p options: Extra options, optional
95  By default the file browser dialog will be work as "open file" in the current working directory.
96 */
97 FileBrowserHandle fileBrowserCreate(bool isEmbed,
98  uintptr_t windowId,
99  double scaleFactor,
100  const FileBrowserOptions& options = FileBrowserOptions());
101 
102 /**
103  Idle the file browser dialog handle.@n
104  Returns true if dialog was closed (with or without a file selection),
105  in which case the handle must not be used afterwards.
106  You can then call fileBrowserGetPath to know the selected file (or null if cancelled).
107 */
108 bool fileBrowserIdle(const FileBrowserHandle handle);
109 
110 /**
111  Close the file browser dialog, handle must not be used afterwards.
112 */
113 void fileBrowserClose(const FileBrowserHandle handle);
114 
115 /**
116  Get the path chosen by the user or null.@n
117  Should only be called after fileBrowserIdle returns true.
118 */
119 const char* fileBrowserGetPath(const FileBrowserHandle handle);
120 
121 // --------------------------------------------------------------------------------------------------------------------
Definition: FileBrowserDialogImpl.cpp:169
Definition: FileBrowserDialogImpl.hpp:62
ButtonState showHidden
Definition: FileBrowserDialogImpl.hpp:66
ButtonState showPlaces
Definition: FileBrowserDialogImpl.hpp:68
Buttons()
Definition: FileBrowserDialogImpl.hpp:71
ButtonState listAllFiles
Definition: FileBrowserDialogImpl.hpp:64
Definition: FileBrowserDialogImpl.hpp:33
const char * title
Definition: FileBrowserDialogImpl.hpp:44
const char * startDir
Definition: FileBrowserDialogImpl.hpp:41
bool saving
Definition: FileBrowserDialogImpl.hpp:35
ButtonState
Definition: FileBrowserDialogImpl.hpp:53
const char * defaultName
Definition: FileBrowserDialogImpl.hpp:38
FileBrowserOptions()
Definition: FileBrowserDialogImpl.hpp:78