コード例 #1
0
//==============================================================================
bool KeyPressMappingSet::keyPressed (const KeyPress& key,
                                     Component* originatingComponent)
{
    bool used = false;

    const CommandID commandID = findCommandForKeyPress (key);

    const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);

    if (ci != 0
         && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
    {
        ApplicationCommandInfo info (0);

        if (commandManager->getTargetForCommand (commandID, info) != 0
             && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
        {
            invokeCommand (commandID, key, true, 0, originatingComponent);
            used = true;
        }
        else
        {
            if (originatingComponent != 0)
                originatingComponent->getLookAndFeel().playAlertSound();
        }
    }

    return used;
}
コード例 #2
0
void KeyPressMappingSet::addKeyPress (const CommandID commandID, const KeyPress& newKeyPress, int insertIndex)
{
    // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
    // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
    jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
                 && ! newKeyPress.getModifiers().isShiftDown()));

    if (findCommandForKeyPress (newKeyPress) != commandID)
    {
        if (newKeyPress.isValid())
        {
            for (int i = mappings.size(); --i >= 0;)
            {
                if (mappings.getUnchecked(i)->commandID == commandID)
                {
                    mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);

                    sendChangeMessage();
                    return;
                }
            }

            if (const ApplicationCommandInfo* const ci = commandManager.getCommandForID (commandID))
            {
                CommandMapping* const cm = new CommandMapping();
                cm->commandID = commandID;
                cm->keypresses.add (newKeyPress);
                cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;

                mappings.add (cm);
                sendChangeMessage();
            }
            else
            {
                // If you hit this, you're trying to attach a keypress to a command ID that
                // doesn't exist, so the key is not being attached.
                jassertfalse;
            }
        }
    }
}