Updated JUCE modules to version 3, which also updated the license headers to reflect AGPLv3 compatibility.

This commit is contained in:
Jonathan Thomas
2014-07-10 14:24:30 -05:00
parent 417648fb9e
commit 3879498af3
891 changed files with 103385 additions and 70181 deletions

View File

@@ -1,24 +1,23 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-11 by Raw Material Software Ltd.
This file is part of the JUCE library.
Copyright (c) 2013 - Raw Material Software Ltd.
------------------------------------------------------------------------------
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3
JUCE can be redistributed and/or modified under the terms of the GNU General
Public License (Version 2), as published by the Free Software Foundation.
A copy of the license is included in the JUCE distribution, or can be found
online at www.gnu.org/licenses.
Details of these licenses can be found at: www.gnu.org/licenses
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.rawmaterialsoftware.com/juce for more information.
available: visit www.juce.com for more information.
==============================================================================
*/
@@ -26,23 +25,21 @@
class KeyMappingEditorComponent::ChangeKeyButton : public Button
{
public:
ChangeKeyButton (KeyMappingEditorComponent& owner_,
const CommandID commandID_,
const String& keyName,
const int keyNum_)
ChangeKeyButton (KeyMappingEditorComponent& kec, const CommandID command,
const String& keyName, const int keyIndex)
: Button (keyName),
owner (owner_),
commandID (commandID_),
keyNum (keyNum_)
owner (kec),
commandID (command),
keyNum (keyIndex)
{
setWantsKeyboardFocus (false);
setTriggeredOnMouseDown (keyNum >= 0);
setTooltip (keyNum_ < 0 ? TRANS("adds a new key-mapping")
: TRANS("click to change this key-mapping"));
setTooltip (keyIndex < 0 ? TRANS("Adds a new key-mapping")
: TRANS("Click to change this key-mapping"));
}
void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/) override
{
getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
keyNum >= 0 ? getName() : String::empty);
@@ -61,15 +58,15 @@ public:
}
}
void clicked()
void clicked() override
{
if (keyNum >= 0)
{
// existing key clicked..
PopupMenu m;
m.addItem (1, TRANS("change this key-mapping"));
m.addItem (1, TRANS("Change this key-mapping"));
m.addSeparator();
m.addItem (2, TRANS("remove this key-mapping"));
m.addItem (2, TRANS("Remove this key-mapping"));
m.showMenuAsync (PopupMenu::Options(),
ModalCallbackFunction::forComponent (menuCallback, this));
@@ -83,27 +80,22 @@ public:
void fitToContent (const int h) noexcept
{
if (keyNum < 0)
{
setSize (h, h);
}
else
{
Font f (h * 0.6f);
setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
}
setSize (jlimit (h * 4, h * 8, 6 + Font (h * 0.6f).getStringWidth (getName())), h);
}
//==============================================================================
class KeyEntryWindow : public AlertWindow
{
public:
KeyEntryWindow (KeyMappingEditorComponent& owner_)
KeyEntryWindow (KeyMappingEditorComponent& kec)
: AlertWindow (TRANS("New key-mapping"),
TRANS("Please press a key combination now..."),
AlertWindow::NoIcon),
owner (owner_)
owner (kec)
{
addButton (TRANS("Ok"), 1);
addButton (TRANS("OK"), 1);
addButton (TRANS("Cancel"), 0);
// (avoid return + escape keys getting processed by the buttons..)
@@ -114,22 +106,24 @@ public:
grabKeyboardFocus();
}
bool keyPressed (const KeyPress& key)
bool keyPressed (const KeyPress& key) override
{
lastPress = key;
String message (TRANS("Key: ") + owner.getDescriptionForKeyPress (key));
String message (TRANS("Key") + ": " + owner.getDescriptionForKeyPress (key));
const CommandID previousCommand = owner.getMappings().findCommandForKeyPress (key);
if (previousCommand != 0)
message << "\n\n" << TRANS("(Currently assigned to \"")
<< owner.getMappings().getCommandManager()->getNameOfCommand (previousCommand) << "\")";
message << "\n\n("
<< TRANS("Currently assigned to \"CMDN\"")
.replace ("CMDN", TRANS (owner.getCommandManager().getNameOfCommand (previousCommand)))
<< ')';
setMessage (message);
return true;
}
bool keyStateChanged (bool)
bool keyStateChanged (bool) override
{
return true;
}
@@ -139,7 +133,7 @@ public:
private:
KeyMappingEditorComponent& owner;
JUCE_DECLARE_NON_COPYABLE (KeyEntryWindow);
JUCE_DECLARE_NON_COPYABLE (KeyEntryWindow)
};
static void assignNewKeyCallback (int result, ChangeKeyButton* button, KeyPress newKey)
@@ -167,9 +161,10 @@ public:
{
AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
TRANS("Change key-mapping"),
TRANS("This key is already assigned to the command \"")
+ owner.getMappings().getCommandManager()->getNameOfCommand (previousCommand)
+ TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
TRANS("This key is already assigned to the command \"CMDN\"")
.replace ("CMDN", owner.getCommandManager().getNameOfCommand (previousCommand))
+ "\n\n"
+ TRANS("Do you want to re-assign it to this new command instead?"),
TRANS("Re-assign"),
TRANS("Cancel"),
this,
@@ -202,21 +197,21 @@ private:
const int keyNum;
ScopedPointer<KeyEntryWindow> currentKeyEntryWindow;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChangeKeyButton);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChangeKeyButton)
};
//==============================================================================
class KeyMappingEditorComponent::ItemComponent : public Component
{
public:
ItemComponent (KeyMappingEditorComponent& owner_, const CommandID commandID_)
: owner (owner_), commandID (commandID_)
ItemComponent (KeyMappingEditorComponent& kec, const CommandID command)
: owner (kec), commandID (command)
{
setInterceptsMouseClicks (false, true);
const bool isReadOnly = owner.isCommandReadOnly (commandID);
const Array <KeyPress> keyPresses (owner.getMappings().getKeyPressesAssignedToCommand (commandID));
const Array<KeyPress> keyPresses (owner.getMappings().getKeyPressesAssignedToCommand (commandID));
for (int i = 0; i < jmin ((int) maxNumAssignments, keyPresses.size()); ++i)
addKeyPressButton (owner.getDescriptionForKeyPress (keyPresses.getReference (i)), i, isReadOnly);
@@ -234,17 +229,17 @@ public:
addChildComponent (b);
}
void paint (Graphics& g)
void paint (Graphics& g) override
{
g.setFont (getHeight() * 0.7f);
g.setColour (findColour (KeyMappingEditorComponent::textColourId));
g.setColour (owner.findColour (KeyMappingEditorComponent::textColourId));
g.drawFittedText (owner.getMappings().getCommandManager()->getNameOfCommand (commandID),
g.drawFittedText (TRANS (owner.getCommandManager().getNameOfCommand (commandID)),
4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
Justification::centredLeft, true);
}
void resized()
void resized() override
{
int x = getWidth() - 4;
@@ -265,32 +260,27 @@ private:
enum { maxNumAssignments = 3 };
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ItemComponent);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ItemComponent)
};
//==============================================================================
class KeyMappingEditorComponent::MappingItem : public TreeViewItem
{
public:
MappingItem (KeyMappingEditorComponent& owner_, const CommandID commandID_)
: owner (owner_), commandID (commandID_)
{
}
MappingItem (KeyMappingEditorComponent& kec, const CommandID command)
: owner (kec), commandID (command)
{}
String getUniqueName() const { return String ((int) commandID) + "_id"; }
bool mightContainSubItems() { return false; }
int getItemHeight() const { return 20; }
Component* createItemComponent()
{
return new ItemComponent (owner, commandID);
}
String getUniqueName() const override { return String ((int) commandID) + "_id"; }
bool mightContainSubItems() override { return false; }
int getItemHeight() const override { return 20; }
Component* createItemComponent() override { return new ItemComponent (owner, commandID); }
private:
KeyMappingEditorComponent& owner;
const CommandID commandID;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MappingItem);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MappingItem)
};
@@ -298,38 +288,33 @@ private:
class KeyMappingEditorComponent::CategoryItem : public TreeViewItem
{
public:
CategoryItem (KeyMappingEditorComponent& owner_, const String& name)
: owner (owner_), categoryName (name)
{
}
CategoryItem (KeyMappingEditorComponent& kec, const String& name)
: owner (kec), categoryName (name)
{}
String getUniqueName() const { return categoryName + "_cat"; }
bool mightContainSubItems() { return true; }
int getItemHeight() const { return 28; }
String getUniqueName() const override { return categoryName + "_cat"; }
bool mightContainSubItems() override { return true; }
int getItemHeight() const override { return 22; }
void paintItem (Graphics& g, int width, int height)
void paintItem (Graphics& g, int width, int height) override
{
g.setFont (height * 0.6f, Font::bold);
g.setFont (Font (height * 0.7f, Font::bold));
g.setColour (owner.findColour (KeyMappingEditorComponent::textColourId));
g.drawText (categoryName,
2, 0, width - 2, height,
Justification::centredLeft, true);
g.drawText (TRANS (categoryName), 2, 0, width - 2, height, Justification::centredLeft, true);
}
void itemOpennessChanged (bool isNowOpen)
void itemOpennessChanged (bool isNowOpen) override
{
if (isNowOpen)
{
if (getNumSubItems() == 0)
{
Array <CommandID> commands (owner.getMappings().getCommandManager()->getCommandsInCategory (categoryName));
const Array<CommandID> commands (owner.getCommandManager().getCommandsInCategory (categoryName));
for (int i = 0; i < commands.size(); ++i)
{
if (owner.shouldCommandBeIncluded (commands[i]))
addSubItem (new MappingItem (owner, commands[i]));
}
if (owner.shouldCommandBeIncluded (commands.getUnchecked(i)))
addSubItem (new MappingItem (owner, commands.getUnchecked(i)));
}
}
else
@@ -342,17 +327,16 @@ private:
KeyMappingEditorComponent& owner;
String categoryName;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CategoryItem);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CategoryItem)
};
//==============================================================================
class KeyMappingEditorComponent::TopLevelItem : public TreeViewItem,
public ChangeListener,
public ButtonListener
public ButtonListener,
private ChangeListener
{
public:
TopLevelItem (KeyMappingEditorComponent& owner_)
: owner (owner_)
TopLevelItem (KeyMappingEditorComponent& kec) : owner (kec)
{
setLinesDrawnForSubItems (false);
owner.getMappings().addChangeListener (this);
@@ -366,20 +350,20 @@ public:
bool mightContainSubItems() { return true; }
String getUniqueName() const { return "keys"; }
void changeListenerCallback (ChangeBroadcaster*)
void changeListenerCallback (ChangeBroadcaster*) override
{
const OpennessRestorer opennessRestorer (*this);
clearSubItems();
const StringArray categories (owner.getMappings().getCommandManager()->getCommandCategories());
const StringArray categories (owner.getCommandManager().getCommandCategories());
for (int i = 0; i < categories.size(); ++i)
{
const Array <CommandID> commands (owner.getMappings().getCommandManager()->getCommandsInCategory (categories[i]));
const Array<CommandID> commands (owner.getCommandManager().getCommandsInCategory (categories[i]));
int count = 0;
for (int j = 0; j < commands.size(); ++j)
if (owner.shouldCommandBeIncluded (commands[j]))
if (owner.shouldCommandBeIncluded (commands.getUnchecked(j)))
++count;
if (count > 0)
@@ -393,7 +377,7 @@ public:
owner->getMappings().resetToDefaultMappings();
}
void buttonClicked (Button*)
void buttonClicked (Button*) override
{
AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
TRANS("Reset to defaults"),
@@ -419,15 +403,16 @@ KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet& mappin
if (showResetToDefaultButton)
{
addAndMakeVisible (&resetButton);
addAndMakeVisible (resetButton);
resetButton.addListener (treeItem);
}
addAndMakeVisible (&tree);
addAndMakeVisible (tree);
tree.setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
tree.setRootItemVisible (false);
tree.setDefaultOpenness (true);
tree.setRootItem (treeItem);
tree.setIndentSize (12);
}
KeyMappingEditorComponent::~KeyMappingEditorComponent()
@@ -436,8 +421,8 @@ KeyMappingEditorComponent::~KeyMappingEditorComponent()
}
//==============================================================================
void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
const Colour& textColour)
void KeyMappingEditorComponent::setColours (Colour mainBackground,
Colour textColour)
{
setColour (backgroundColourId, mainBackground);
setColour (textColourId, textColour);
@@ -469,14 +454,14 @@ void KeyMappingEditorComponent::resized()
//==============================================================================
bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
{
const ApplicationCommandInfo* const ci = mappings.getCommandManager()->getCommandForID (commandID);
const ApplicationCommandInfo* const ci = mappings.getCommandManager().getCommandForID (commandID);
return ci != nullptr && (ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0;
}
bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
{
const ApplicationCommandInfo* const ci = mappings.getCommandManager()->getCommandForID (commandID);
const ApplicationCommandInfo* const ci = mappings.getCommandManager().getCommandForID (commandID);
return ci != nullptr && (ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0;
}