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.

103 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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_FILELISTCOMPONENT_JUCEHEADER__
  19. #define __JUCE_FILELISTCOMPONENT_JUCEHEADER__
  20. #include "juce_DirectoryContentsDisplayComponent.h"
  21. #include "juce_FileBrowserListener.h"
  22. #include "../widgets/juce_ListBox.h"
  23. #include "../widgets/juce_TreeView.h"
  24. //==============================================================================
  25. /**
  26. A component that displays the files in a directory as a listbox.
  27. This implements the DirectoryContentsDisplayComponent base class so that
  28. it can be used in a FileBrowserComponent.
  29. To attach a listener to it, use its DirectoryContentsDisplayComponent base
  30. class and the FileBrowserListener class.
  31. @see DirectoryContentsList, FileTreeComponent
  32. */
  33. class JUCE_API FileListComponent : public ListBox,
  34. public DirectoryContentsDisplayComponent,
  35. private ListBoxModel,
  36. private ChangeListener
  37. {
  38. public:
  39. //==============================================================================
  40. /** Creates a listbox to show the contents of a specified directory.
  41. */
  42. FileListComponent (DirectoryContentsList& listToShow);
  43. /** Destructor. */
  44. ~FileListComponent();
  45. //==============================================================================
  46. /** Returns the number of files the user has got selected.
  47. @see getSelectedFile
  48. */
  49. int getNumSelectedFiles() const;
  50. /** Returns one of the files that the user has currently selected.
  51. The index should be in the range 0 to (getNumSelectedFiles() - 1).
  52. @see getNumSelectedFiles
  53. */
  54. File getSelectedFile (int index = 0) const;
  55. /** Deselects any files that are currently selected. */
  56. void deselectAllFiles();
  57. /** Scrolls to the top of the list. */
  58. void scrollToTop();
  59. /** If the specified file is in the list, it will become the only selected item
  60. (and if the file isn't in the list, all other items will be deselected). */
  61. void setSelectedFile (const File&);
  62. private:
  63. //==============================================================================
  64. File lastDirectory;
  65. class ItemComponent;
  66. void changeListenerCallback (ChangeBroadcaster*);
  67. int getNumRows();
  68. void paintListBoxItem (int, Graphics&, int, int, bool);
  69. Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate);
  70. void selectedRowsChanged (int lastRowSelected);
  71. void deleteKeyPressed (int currentSelectedRow);
  72. void returnKeyPressed (int currentSelectedRow);
  73. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileListComponent);
  74. };
  75. #endif // __JUCE_FILELISTCOMPONENT_JUCEHEADER__