DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.7KB

  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. #ifndef DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
  17. #define DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
  18. #include "../DistrhoUtils.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // --------------------------------------------------------------------------------------------------------------------
  21. // File Browser Dialog stuff
  22. struct FileBrowserData;
  23. typedef FileBrowserData* FileBrowserHandle;
  24. // --------------------------------------------------------------------------------------------------------------------
  25. /**
  26. File browser options, for customizing the file browser dialog.@n
  27. By default the file browser dialog will be work as "open file" in the current working directory.
  28. */
  29. struct FileBrowserOptions {
  30. /** Whether we are saving, opening files otherwise (default) */
  31. bool saving;
  32. /** Start directory, uses current working directory if null */
  33. const char* startDir;
  34. /** File browser dialog window title, uses "FileBrowser" if null */
  35. const char* title;
  36. // TODO file filter
  37. /**
  38. File browser button state.
  39. This allows to customize the behaviour of the file browse dialog buttons.
  40. Note these are merely hints, not all systems support them.
  41. */
  42. enum ButtonState {
  43. kButtonInvisible,
  44. kButtonVisibleUnchecked,
  45. kButtonVisibleChecked,
  46. };
  47. /**
  48. File browser buttons.
  49. */
  50. struct Buttons {
  51. /** Whether to list all files vs only those with matching file extension */
  52. ButtonState listAllFiles;
  53. /** Whether to show hidden files */
  54. ButtonState showHidden;
  55. /** Whether to show list of places (bookmarks) */
  56. ButtonState showPlaces;
  57. /** Constructor for default values */
  58. Buttons()
  59. : listAllFiles(kButtonVisibleChecked),
  60. showHidden(kButtonVisibleUnchecked),
  61. showPlaces(kButtonVisibleChecked) {}
  62. } buttons;
  63. /** Constructor for default values */
  64. FileBrowserOptions()
  65. : saving(false),
  66. startDir(nullptr),
  67. title(nullptr),
  68. buttons() {}
  69. };
  70. // --------------------------------------------------------------------------------------------------------------------
  71. #ifdef DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE
  72. namespace DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE {
  73. #endif
  74. /**
  75. Create a new file browser dialog.
  76. @p isEmbed: Whether the window this dialog belongs to is an embed/child window (needed to close dialog on Windows)
  77. @p windowId: The native window id to attach this dialog to as transient parent (X11 Window, HWND or NSView*)
  78. @p scaleFactor: Scale factor to use (only used on X11)
  79. @p options: Extra options, optional
  80. By default the file browser dialog will be work as "open file" in the current working directory.
  81. */
  82. FileBrowserHandle fileBrowserCreate(bool isEmbed,
  83. uintptr_t windowId,
  84. double scaleFactor,
  85. const FileBrowserOptions& options = FileBrowserOptions());
  86. /**
  87. Idle the file browser dialog handle.@n
  88. Returns true if dialog was closed (with or without a file selection),
  89. in which case the handle must not be used afterwards.
  90. You can then call fileBrowserGetPath to know the selected file (or null if cancelled).
  91. */
  92. bool fileBrowserIdle(const FileBrowserHandle handle);
  93. /**
  94. Close the file browser dialog, handle must not be used afterwards.
  95. */
  96. void fileBrowserClose(const FileBrowserHandle handle);
  97. /**
  98. Get the path chosen by the user or null.@n
  99. Should only be called after fileBrowserIdle returns true.
  100. */
  101. const char* fileBrowserGetPath(const FileBrowserHandle handle);
  102. // --------------------------------------------------------------------------------------------------------------------
  103. #ifdef DISTRHO_FILE_BROWSER_DIALOG_EXTRA_NAMESPACE
  104. }
  105. #endif
  106. // --------------------------------------------------------------------------------------------------------------------
  107. END_NAMESPACE_DISTRHO
  108. #endif // DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED