Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / JuceDemo / Source / demos / DragAndDropDemo.cpp
blob0121322254cdbbaa13e9a6e5ea73a582750d6f9f
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-9 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../jucedemo_headers.h"
28 //==============================================================================
29 // this is the listbox containing the draggable source components..
31 class DragAndDropDemoSource : public ListBox,
32 public ListBoxModel
34 public:
35 //==============================================================================
36 DragAndDropDemoSource()
37 : ListBox ("d+d source", 0)
39 // tells the ListBox that this object supplies the info about its rows.
40 setModel (this);
42 setMultipleSelectionEnabled (true);
45 ~DragAndDropDemoSource()
49 //==============================================================================
50 // The following methods implement the necessary virtual functions from ListBoxModel,
51 // telling the listbox how many rows there are, painting them, etc.
52 int getNumRows()
54 return 30;
57 void paintListBoxItem (int rowNumber,
58 Graphics& g,
59 int width, int height,
60 bool rowIsSelected)
62 if (rowIsSelected)
63 g.fillAll (Colours::lightblue);
65 g.setColour (Colours::black);
66 g.setFont (height * 0.7f);
68 g.drawText ("Row Number " + String (rowNumber + 1),
69 5, 0, width, height,
70 Justification::centredLeft, true);
73 const var getDragSourceDescription (const SparseSet<int>& selectedRows)
75 // for our drag desctription, we'll just make a list of the selected
76 // row numbers - this will be picked up by the drag target and displayed in
77 // its box.
78 String desc;
80 for (int i = 0; i < selectedRows.size(); ++i)
81 desc << (selectedRows [i] + 1) << " ";
83 return desc.trim();
86 //==============================================================================
87 // this just fills in the background of the listbox
88 void paint (Graphics& g)
90 g.fillAll (Colours::white.withAlpha (0.7f));
95 //==============================================================================
96 // and this is a component that can have things dropped onto it..
98 class DragAndDropDemoTarget : public Component,
99 public DragAndDropTarget,
100 public FileDragAndDropTarget
102 public:
103 //==============================================================================
104 DragAndDropDemoTarget()
105 : message ("Drag-and-drop some rows from the top-left box onto this component!\n\n"
106 "You can also drag-and-drop files here"),
107 somethingIsBeingDraggedOver (false)
111 ~DragAndDropDemoTarget()
115 //==============================================================================
116 void paint (Graphics& g)
118 g.fillAll (Colours::green.withAlpha (0.2f));
120 // draw a red line around the comp if the user's currently dragging something over it..
121 if (somethingIsBeingDraggedOver)
123 g.setColour (Colours::red);
124 g.drawRect (0, 0, getWidth(), getHeight(), 3);
127 g.setColour (Colours::black);
128 g.setFont (14.0f);
129 g.drawFittedText (message, 10, 0, getWidth() - 20, getHeight(), Justification::centred, 4);
132 //==============================================================================
133 // These methods implement the DragAndDropTarget interface, and allow our component
134 // to accept drag-and-drop of objects from other Juce components..
136 bool isInterestedInDragSource (const SourceDetails& /*dragSourceDetails*/)
138 // normally you'd check the sourceDescription value to see if it's the
139 // sort of object that you're interested in before returning true, but for
140 // the demo, we'll say yes to anything..
141 return true;
144 void itemDragEnter (const SourceDetails& /*dragSourceDetails*/)
146 somethingIsBeingDraggedOver = true;
147 repaint();
150 void itemDragMove (const SourceDetails& /*dragSourceDetails*/)
154 void itemDragExit (const SourceDetails& /*dragSourceDetails*/)
156 somethingIsBeingDraggedOver = false;
157 repaint();
160 void itemDropped (const SourceDetails& dragSourceDetails)
162 message = "last rows dropped: " + dragSourceDetails.description.toString();
164 somethingIsBeingDraggedOver = false;
165 repaint();
169 //==============================================================================
170 // These methods implement the FileDragAndDropTarget interface, and allow our component
171 // to accept drag-and-drop of files..
173 bool isInterestedInFileDrag (const StringArray& /*files*/)
175 // normally you'd check these files to see if they're something that you're
176 // interested in before returning true, but for the demo, we'll say yes to anything..
177 return true;
180 void fileDragEnter (const StringArray& /*files*/, int /*x*/, int /*y*/)
182 somethingIsBeingDraggedOver = true;
183 repaint();
186 void fileDragMove (const StringArray& /*files*/, int /*x*/, int /*y*/)
190 void fileDragExit (const StringArray& /*files*/)
192 somethingIsBeingDraggedOver = false;
193 repaint();
196 void filesDropped (const StringArray& files, int /*x*/, int /*y*/)
198 message = "files dropped: " + files.joinIntoString ("\n");
200 somethingIsBeingDraggedOver = false;
201 repaint();
204 private:
205 String message;
206 bool somethingIsBeingDraggedOver;
210 //==============================================================================
211 class DragAndDropDemo : public Component,
212 public DragAndDropContainer
214 public:
215 //==============================================================================
216 DragAndDropDemo()
218 setName ("Drag-and-Drop");
220 addAndMakeVisible (&source);
221 addAndMakeVisible (&target);
224 ~DragAndDropDemo()
228 void resized()
230 source.setBounds (10, 10, 250, 150);
231 target.setBounds (getWidth() - 260, getHeight() - 160, 250, 150);
234 private:
235 DragAndDropDemoSource source;
236 DragAndDropDemoTarget target;
238 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DragAndDropDemo);
242 //==============================================================================
243 Component* createDragAndDropDemo()
245 return new DragAndDropDemo();