LMMS
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
50 int numCtrlAltCommandKeys = 0;
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())
67 ++numCtrlAltCommandKeys;
68 #endif
69
70 if (numCtrlAltCommandKeys < 2)
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
92 return target.copyToClipboard();
93
96 return target.cutToClipboard();
97
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
110 return target.selectAll();
111
113 return target.undo();
114
117 return target.redo();
118
119 return false;
120 }
121};
122
123} // namespace juce
Definition juce_KeyPress.h:40
static const int homeKey
Definition juce_KeyPress.h:204
static const int upKey
Definition juce_KeyPress.h:198
static const int endKey
Definition juce_KeyPress.h:205
static const int rightKey
Definition juce_KeyPress.h:201
static const int deleteKey
Definition juce_KeyPress.h:194
static const int insertKey
Definition juce_KeyPress.h:196
static const int downKey
Definition juce_KeyPress.h:199
static const int leftKey
Definition juce_KeyPress.h:200
static const int pageUpKey
Definition juce_KeyPress.h:202
static const int pageDownKey
Definition juce_KeyPress.h:203
static const int backspaceKey
Definition juce_KeyPress.h:195
@ ctrlModifier
Definition juce_ModifierKeys.h:124
@ commandModifier
Definition juce_ModifierKeys.h:147
@ shiftModifier
Definition juce_ModifierKeys.h:121
Definition carla_juce.cpp:31
Definition juce_TextEditorKeyMapper.h:39
static bool invokeKeyFunction(CallbackClass &target, const KeyPress &key)
Definition juce_TextEditorKeyMapper.h:43
ZCONST char * key
Definition crypt.c:587