mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Minor fixes + cleanups to TextEditor.
This commit is contained in:
parent
7f0e28c983
commit
f8b5da8b1e
2 changed files with 43 additions and 41 deletions
|
|
@ -49,7 +49,7 @@ struct TextAtom
|
|||
return atomText.substring (0, numChars);
|
||||
|
||||
if (isNewLine())
|
||||
return String::empty;
|
||||
return String();
|
||||
|
||||
return String::repeatedString (String::charToString (passwordCharacter), numChars);
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ public:
|
|||
|
||||
UniformTextSection* split (const int indexToBreakAt, const juce_wchar passwordChar)
|
||||
{
|
||||
UniformTextSection* const section2 = new UniformTextSection (String::empty, font, colour, passwordChar);
|
||||
UniformTextSection* const section2 = new UniformTextSection (String(), font, colour, passwordChar);
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < atoms.size(); ++i)
|
||||
|
|
@ -902,6 +902,7 @@ TextEditor::TextEditor (const String& name,
|
|||
: Component (name),
|
||||
borderSize (1, 1, 1, 3),
|
||||
readOnly (false),
|
||||
caretVisible (true),
|
||||
multiline (false),
|
||||
wordWrap (false),
|
||||
returnKeyStartsNewLine (false),
|
||||
|
|
@ -933,7 +934,7 @@ TextEditor::TextEditor (const String& name,
|
|||
viewport->setScrollBarsShown (false, false);
|
||||
|
||||
setWantsKeyboardFocus (true);
|
||||
setCaretVisible (true);
|
||||
recreateCaret();
|
||||
}
|
||||
|
||||
TextEditor::~TextEditor()
|
||||
|
|
@ -1020,7 +1021,7 @@ void TextEditor::setReadOnly (const bool shouldBeReadOnly)
|
|||
}
|
||||
}
|
||||
|
||||
bool TextEditor::isReadOnly() const
|
||||
bool TextEditor::isReadOnly() const noexcept
|
||||
{
|
||||
return readOnly || ! isEnabled();
|
||||
}
|
||||
|
|
@ -1084,20 +1085,27 @@ void TextEditor::colourChanged()
|
|||
void TextEditor::lookAndFeelChanged()
|
||||
{
|
||||
recreateCaret();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void TextEditor::enablementChanged()
|
||||
{
|
||||
recreateCaret();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
|
||||
{
|
||||
if (caretVisible != shouldCaretBeVisible)
|
||||
{
|
||||
caretVisible = shouldCaretBeVisible;
|
||||
recreateCaret();
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::recreateCaret()
|
||||
{
|
||||
if (isCaretVisible())
|
||||
{
|
||||
setCaretVisible (false);
|
||||
setCaretVisible (true);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
|
||||
{
|
||||
if (shouldCaretBeVisible && ! isReadOnly())
|
||||
{
|
||||
if (caret == nullptr)
|
||||
{
|
||||
|
|
@ -1139,8 +1147,7 @@ void TextEditor::setInputFilter (InputFilter* newFilter, bool takeOwnership)
|
|||
inputFilter.set (newFilter, takeOwnership);
|
||||
}
|
||||
|
||||
void TextEditor::setInputRestrictions (const int maxLen,
|
||||
const String& chars)
|
||||
void TextEditor::setInputRestrictions (const int maxLen, const String& chars)
|
||||
{
|
||||
setInputFilter (new LengthAndCharacterRestriction (maxLen, chars), true);
|
||||
}
|
||||
|
|
@ -1570,7 +1577,7 @@ void TextEditor::cut()
|
|||
if (! isReadOnly())
|
||||
{
|
||||
moveCaret (selection.getEnd());
|
||||
insertTextAtCaret (String::empty);
|
||||
insertTextAtCaret (String());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2131,12 +2138,6 @@ void TextEditor::handleCommandMessage (const int commandId)
|
|||
}
|
||||
}
|
||||
|
||||
void TextEditor::enablementChanged()
|
||||
{
|
||||
recreateCaret();
|
||||
repaint();
|
||||
}
|
||||
|
||||
void TextEditor::setTemporaryUnderlining (const Array<Range<int> >& newUnderlinedSections)
|
||||
{
|
||||
underlinedSections = newUnderlinedSections;
|
||||
|
|
@ -2361,7 +2362,7 @@ String TextEditor::getText() const
|
|||
String TextEditor::getTextInRange (const Range<int>& range) const
|
||||
{
|
||||
if (range.isEmpty())
|
||||
return String::empty;
|
||||
return String();
|
||||
|
||||
MemoryOutputStream mo;
|
||||
mo.preallocate ((size_t) jmin (getTotalNumChars(), range.getLength()));
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public:
|
|||
for a black splodge (not all fonts include this, though), or 0x2022,
|
||||
which is a bullet (probably the best choice for linux).
|
||||
*/
|
||||
explicit TextEditor (const String& componentName = String::empty,
|
||||
explicit TextEditor (const String& componentName = String(),
|
||||
juce_wchar passwordCharacter = 0);
|
||||
|
||||
/** Destructor. */
|
||||
|
|
@ -123,7 +123,7 @@ public:
|
|||
void setReadOnly (bool shouldBeReadOnly);
|
||||
|
||||
/** Returns true if the editor is in read-only mode. */
|
||||
bool isReadOnly() const;
|
||||
bool isReadOnly() const noexcept;
|
||||
|
||||
//==============================================================================
|
||||
/** Makes the caret visible or invisible.
|
||||
|
|
@ -135,7 +135,7 @@ public:
|
|||
/** Returns true if the caret is enabled.
|
||||
@see setCaretVisible
|
||||
*/
|
||||
bool isCaretVisible() const noexcept { return caret != nullptr; }
|
||||
bool isCaretVisible() const noexcept { return caretVisible && ! isReadOnly(); }
|
||||
|
||||
//==============================================================================
|
||||
/** Enables/disables a vertical scrollbar.
|
||||
|
|
@ -347,7 +347,7 @@ public:
|
|||
this string, otherwise it will be inserted.
|
||||
|
||||
To delete a section of text, you can use setHighlightedRegion() to
|
||||
highlight it, and call insertTextAtCursor (String::empty).
|
||||
highlight it, and call insertTextAtCaret (String()).
|
||||
|
||||
@see setCaretPosition, getCaretPosition, setHighlightedRegion
|
||||
*/
|
||||
|
|
@ -583,7 +583,7 @@ public:
|
|||
this string are allowed to be entered into the editor.
|
||||
*/
|
||||
void setInputRestrictions (int maxTextLength,
|
||||
const String& allowedCharacters = String::empty);
|
||||
const String& allowedCharacters = String());
|
||||
|
||||
void setKeyboardType (VirtualKeyboardType type) noexcept { keyboardType = type; }
|
||||
|
||||
|
|
@ -670,19 +670,20 @@ private:
|
|||
TextHolderComponent* textHolder;
|
||||
BorderSize<int> borderSize;
|
||||
|
||||
bool readOnly : 1;
|
||||
bool multiline : 1;
|
||||
bool wordWrap : 1;
|
||||
bool returnKeyStartsNewLine : 1;
|
||||
bool popupMenuEnabled : 1;
|
||||
bool selectAllTextWhenFocused : 1;
|
||||
bool scrollbarVisible : 1;
|
||||
bool wasFocused : 1;
|
||||
bool keepCaretOnScreen : 1;
|
||||
bool tabKeyUsed : 1;
|
||||
bool menuActive : 1;
|
||||
bool valueTextNeedsUpdating : 1;
|
||||
bool consumeEscAndReturnKeys : 1;
|
||||
bool readOnly;
|
||||
bool caretVisible;
|
||||
bool multiline;
|
||||
bool wordWrap;
|
||||
bool returnKeyStartsNewLine;
|
||||
bool popupMenuEnabled;
|
||||
bool selectAllTextWhenFocused;
|
||||
bool scrollbarVisible;
|
||||
bool wasFocused;
|
||||
bool keepCaretOnScreen;
|
||||
bool tabKeyUsed;
|
||||
bool menuActive;
|
||||
bool valueTextNeedsUpdating;
|
||||
bool consumeEscAndReturnKeys;
|
||||
|
||||
UndoManager undoManager;
|
||||
ScopedPointer<CaretComponent> caret;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue