JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_TextEditorKeyMapper.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
37template <class CallbackClass>
39{
43 static bool invokeKeyFunction (CallbackClass& target, const KeyPress& key)
44 {
45 auto mods = key.getModifiers();
46
47 const bool isShiftDown = mods.isShiftDown();
48 const bool ctrlOrAltDown = mods.isCtrlDown() || mods.isAltDown();
49
51 if (mods.isCtrlDown()) ++numCtrlAltCommandKeys;
52 if (mods.isAltDown()) ++numCtrlAltCommandKeys;
53
54 if (key == KeyPress (KeyPress::downKey, ModifierKeys::ctrlModifier, 0) && target.scrollUp()) return true;
55 if (key == KeyPress (KeyPress::upKey, ModifierKeys::ctrlModifier, 0) && target.scrollDown()) return true;
56
57 #if JUCE_MAC
58 if (mods.isCommandDown() && ! ctrlOrAltDown)
59 {
60 if (key.isKeyCode (KeyPress::upKey)) return target.moveCaretToTop (isShiftDown);
61 if (key.isKeyCode (KeyPress::downKey)) return target.moveCaretToEnd (isShiftDown);
62 if (key.isKeyCode (KeyPress::leftKey)) return target.moveCaretToStartOfLine (isShiftDown);
63 if (key.isKeyCode (KeyPress::rightKey)) return target.moveCaretToEndOfLine (isShiftDown);
64 }
65
66 if (mods.isCommandDown())
68 #endif
69
71 {
72 if (key.isKeyCode (KeyPress::leftKey)) return target.moveCaretLeft (ctrlOrAltDown, isShiftDown);
73 if (key.isKeyCode (KeyPress::rightKey)) return target.moveCaretRight (ctrlOrAltDown, isShiftDown);
74
75 if (key.isKeyCode (KeyPress::homeKey)) return ctrlOrAltDown ? target.moveCaretToTop (isShiftDown)
76 : target.moveCaretToStartOfLine (isShiftDown);
77 if (key.isKeyCode (KeyPress::endKey)) return ctrlOrAltDown ? target.moveCaretToEnd (isShiftDown)
78 : target.moveCaretToEndOfLine (isShiftDown);
79 }
80
81 if (numCtrlAltCommandKeys == 0)
82 {
83 if (key.isKeyCode (KeyPress::upKey)) return target.moveCaretUp (isShiftDown);
84 if (key.isKeyCode (KeyPress::downKey)) return target.moveCaretDown (isShiftDown);
85
86 if (key.isKeyCode (KeyPress::pageUpKey)) return target.pageUp (isShiftDown);
87 if (key.isKeyCode (KeyPress::pageDownKey)) return target.pageDown (isShiftDown);
88 }
89
90 if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
92 return target.copyToClipboard();
93
94 if (key == KeyPress ('x', ModifierKeys::commandModifier, 0)
96 return target.cutToClipboard();
97
98 if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
100 return target.pasteFromClipboard();
101
102 // NB: checking for delete must happen after the earlier check for shift + delete
103 if (numCtrlAltCommandKeys < 2)
104 {
105 if (key.isKeyCode (KeyPress::backspaceKey)) return target.deleteBackwards (ctrlOrAltDown);
106 if (key.isKeyCode (KeyPress::deleteKey)) return target.deleteForwards (ctrlOrAltDown);
107 }
108
109 if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
110 return target.selectAll();
111
112 if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
113 return target.undo();
114
115 if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
117 return target.redo();
118
119 return false;
120 }
121};
122
123} // namespace juce
Represents a key press, including any modifier keys that are needed.
static const int homeKey
key-code for the home key
static const int upKey
key-code for the cursor-up key
static const int endKey
key-code for the end key
bool isKeyCode(int keyCodeToCompare) const noexcept
Checks whether the KeyPress's key is the same as the one provided, without checking the modifiers.
static const int rightKey
key-code for the cursor-right key
static const int deleteKey
key-code for the delete key (not backspace)
static const int insertKey
key-code for the insert key
ModifierKeys getModifiers() const noexcept
Returns the key modifiers.
static const int downKey
key-code for the cursor-down key
static const int leftKey
key-code for the cursor-left key
static const int pageUpKey
key-code for the page-up key
static const int pageDownKey
key-code for the page-down key
static const int backspaceKey
key-code for the backspace key
bool isShiftDown() const noexcept
Checks whether the shift key's flag is set.
@ ctrlModifier
CTRL key flag.
@ commandModifier
Command key flag - on windows this is the same as the CTRL key flag.
@ shiftModifier
Shift key flag.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
This class is used to invoke a range of text-editor navigation methods on an object,...
static bool invokeKeyFunction(CallbackClass &target, const KeyPress &key)
Checks the keypress and invokes one of a range of navigation functions that the target class must imp...