The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

172 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  19. #define __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__
  20. #include "juce_FileBrowserComponent.h"
  21. #include "../windows/juce_ResizableWindow.h"
  22. #include "../buttons/juce_TextButton.h"
  23. #include "../../graphics/fonts/juce_GlyphArrangement.h"
  24. //==============================================================================
  25. /**
  26. A file open/save dialog box.
  27. This is a Juce-based file dialog box; to use a native file chooser, see the
  28. FileChooser class.
  29. To use one of these, create it and call its show() method. e.g.
  30. @code
  31. {
  32. WildcardFileFilter wildcardFilter ("*.foo", "Foo files");
  33. FileBrowserComponent browser (FileBrowserComponent::loadFileMode,
  34. File::nonexistent,
  35. &wildcardFilter,
  36. 0);
  37. FileChooserDialogBox dialogBox ("Open some kind of file",
  38. "Please choose some kind of file that you want to open...",
  39. browser,
  40. getLookAndFeel().alertWindowBackground);
  41. if (dialogBox.show())
  42. {
  43. File selectedFile = browser.getCurrentFile();
  44. ...
  45. }
  46. }
  47. @endcode
  48. @see FileChooser
  49. */
  50. class JUCE_API FileChooserDialogBox : public ResizableWindow,
  51. public ButtonListener,
  52. public FileBrowserListener
  53. {
  54. public:
  55. //==============================================================================
  56. /** Creates a file chooser box.
  57. @param title the main title to show at the top of the box
  58. @param instructions an optional longer piece of text to show below the title in
  59. a smaller font, describing in more detail what's required.
  60. @param browserComponent a FileBrowserComponent that will be shown inside this dialog
  61. box. Make sure you delete this after (but not before!) the
  62. dialog box has been deleted.
  63. @param warnAboutOverwritingExistingFiles if true, then the user will be asked to confirm
  64. if they try to select a file that already exists. (This
  65. flag is only used when saving files)
  66. @param backgroundColour the background colour for the top level window
  67. @see FileBrowserComponent, FilePreviewComponent
  68. */
  69. FileChooserDialogBox (const String& title,
  70. const String& instructions,
  71. FileBrowserComponent& browserComponent,
  72. bool warnAboutOverwritingExistingFiles,
  73. const Colour& backgroundColour);
  74. /** Destructor. */
  75. ~FileChooserDialogBox();
  76. //==============================================================================
  77. /** Displays and runs the dialog box modally.
  78. This will show the box with the specified size, returning true if the user
  79. pressed 'ok', or false if they cancelled.
  80. Leave the width or height as 0 to use the default size
  81. */
  82. bool show (int width = 0, int height = 0);
  83. /** Displays and runs the dialog box modally.
  84. This will show the box with the specified size at the specified location,
  85. returning true if the user pressed 'ok', or false if they cancelled.
  86. Leave the width or height as 0 to use the default size.
  87. */
  88. bool showAt (int x, int y, int width, int height);
  89. //==============================================================================
  90. /** A set of colour IDs to use to change the colour of various aspects of the box.
  91. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  92. methods.
  93. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  94. */
  95. enum ColourIds
  96. {
  97. titleTextColourId = 0x1000850, /**< The colour to use to draw the box's title. */
  98. };
  99. //==============================================================================
  100. /** @internal */
  101. void buttonClicked (Button* button);
  102. /** @internal */
  103. void closeButtonPressed();
  104. /** @internal */
  105. void selectionChanged();
  106. /** @internal */
  107. void fileClicked (const File& file, const MouseEvent& e);
  108. /** @internal */
  109. void fileDoubleClicked (const File& file);
  110. juce_UseDebuggingNewOperator
  111. private:
  112. class ContentComponent : public Component
  113. {
  114. public:
  115. ContentComponent();
  116. ~ContentComponent();
  117. void paint (Graphics& g);
  118. void resized();
  119. String instructions;
  120. GlyphArrangement text;
  121. FileBrowserComponent* chooserComponent;
  122. FilePreviewComponent* previewComponent;
  123. TextButton* okButton;
  124. TextButton* cancelButton;
  125. };
  126. ContentComponent* content;
  127. const bool warnAboutOverwritingExistingFiles;
  128. FileChooserDialogBox (const FileChooserDialogBox&);
  129. FileChooserDialogBox& operator= (const FileChooserDialogBox&);
  130. };
  131. #endif // __JUCE_FILECHOOSERDIALOGBOX_JUCEHEADER__