DISTRHO Plugin Framework
FileBrowserDialog.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 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 #ifndef DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
18 #define DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
19 
20 #include "../DistrhoUtils.hpp"
21 
23 
24 // --------------------------------------------------------------------------------------------------------------------
25 // File Browser Dialog stuff
26 
27 struct FileBrowserData;
29 
30 // --------------------------------------------------------------------------------------------------------------------
31 
32 /**
33  File browser options, for customizing the file browser dialog.@n
34  By default the file browser dialog will be work as "open file" in the current working directory.
35 */
37  /** Whether we are saving, opening files otherwise (default) */
38  bool saving;
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  startDir(nullptr),
81  title(nullptr),
82  buttons() {}
83 };
84 
85 // --------------------------------------------------------------------------------------------------------------------
86 
87 #ifdef DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE
88 namespace DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE {
89 #endif
90 
91 /**
92  Create a new file browser dialog.
93 
94  @p isEmbed: Whether the window this dialog belongs to is an embed/child window (needed to close dialog on Windows)
95  @p windowId: The native window id to attach this dialog to as transient parent (X11 Window, HWND or NSView*)
96  @p scaleFactor: Scale factor to use (only used on X11)
97  @p options: Extra options, optional
98  By default the file browser dialog will be work as "open file" in the current working directory.
99 */
100 FileBrowserHandle fileBrowserCreate(bool isEmbed,
101  uintptr_t windowId,
102  double scaleFactor,
103  const FileBrowserOptions& options = FileBrowserOptions());
104 
105 /**
106  Idle the file browser dialog handle.@n
107  Returns true if dialog was closed (with or without a file selection),
108  in which case the handle must not be used afterwards.
109  You can then call fileBrowserGetPath to know the selected file (or null if cancelled).
110 */
111 bool fileBrowserIdle(const FileBrowserHandle handle);
112 
113 /**
114  Close the file browser dialog, handle must not be used afterwards.
115 */
116 void fileBrowserClose(const FileBrowserHandle handle);
117 
118 /**
119  Get the path chosen by the user or null.@n
120  Should only be called after fileBrowserIdle returns true.
121 */
122 const char* fileBrowserGetPath(const FileBrowserHandle handle);
123 
124 // --------------------------------------------------------------------------------------------------------------------
125 
126 #ifdef DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE
127 }
128 #endif
129 
130 // --------------------------------------------------------------------------------------------------------------------
131 
133 
134 #endif // DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
FileBrowserOptions::startDir
const char * startDir
Definition: FileBrowserDialog.hpp:41
START_NAMESPACE_DISTRHO
#define START_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:828
FileBrowserOptions::ButtonState
ButtonState
Definition: FileBrowserDialog.hpp:53
FileBrowserOptions::title
const char * title
Definition: FileBrowserDialog.hpp:44
END_NAMESPACE_DISTRHO
#define END_NAMESPACE_DISTRHO
Definition: DistrhoInfo.hpp:834
FileBrowserOptions::FileBrowserOptions
FileBrowserOptions()
Definition: FileBrowserDialog.hpp:78
FileBrowserOptions::Buttons::showPlaces
ButtonState showPlaces
Definition: FileBrowserDialog.hpp:68
FileBrowserOptions::Buttons::showHidden
ButtonState showHidden
Definition: FileBrowserDialog.hpp:66
FileBrowserOptions::Buttons
Definition: FileBrowserDialog.hpp:62
FileBrowserOptions::Buttons::Buttons
Buttons()
Definition: FileBrowserDialog.hpp:71
FileBrowserOptions::Buttons::listAllFiles
ButtonState listAllFiles
Definition: FileBrowserDialog.hpp:64
FileBrowserData
Definition: FileBrowserDialog.cpp:50
FileBrowserOptions
Definition: FileBrowserDialog.hpp:36
FileBrowserOptions::saving
bool saving
Definition: FileBrowserDialog.hpp:38