Browse Source

Minor fixes + cleanups to TextEditor.

tags/2021-05-28
jules 9 years ago
parent
commit
f8b5da8b1e
2 changed files with 40 additions and 38 deletions
  1. +21
    -20
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp
  2. +19
    -18
      modules/juce_gui_basics/widgets/juce_TextEditor.h

+ 21
- 20
modules/juce_gui_basics/widgets/juce_TextEditor.cpp View File

@@ -49,7 +49,7 @@ struct TextAtom
return atomText.substring (0, numChars); return atomText.substring (0, numChars);
if (isNewLine()) if (isNewLine())
return String::empty;
return String();
return String::repeatedString (String::charToString (passwordCharacter), numChars); return String::repeatedString (String::charToString (passwordCharacter), numChars);
} }
@@ -111,7 +111,7 @@ public:
UniformTextSection* split (const int indexToBreakAt, const juce_wchar passwordChar) 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; int index = 0;
for (int i = 0; i < atoms.size(); ++i) for (int i = 0; i < atoms.size(); ++i)
@@ -902,6 +902,7 @@ TextEditor::TextEditor (const String& name,
: Component (name), : Component (name),
borderSize (1, 1, 1, 3), borderSize (1, 1, 1, 3),
readOnly (false), readOnly (false),
caretVisible (true),
multiline (false), multiline (false),
wordWrap (false), wordWrap (false),
returnKeyStartsNewLine (false), returnKeyStartsNewLine (false),
@@ -933,7 +934,7 @@ TextEditor::TextEditor (const String& name,
viewport->setScrollBarsShown (false, false); viewport->setScrollBarsShown (false, false);
setWantsKeyboardFocus (true); setWantsKeyboardFocus (true);
setCaretVisible (true);
recreateCaret();
} }
TextEditor::~TextEditor() TextEditor::~TextEditor()
@@ -1020,7 +1021,7 @@ void TextEditor::setReadOnly (const bool shouldBeReadOnly)
} }
} }
bool TextEditor::isReadOnly() const
bool TextEditor::isReadOnly() const noexcept
{ {
return readOnly || ! isEnabled(); return readOnly || ! isEnabled();
} }
@@ -1084,20 +1085,27 @@ void TextEditor::colourChanged()
void TextEditor::lookAndFeelChanged() void TextEditor::lookAndFeelChanged()
{ {
recreateCaret(); recreateCaret();
repaint();
} }
void TextEditor::recreateCaret()
void TextEditor::enablementChanged()
{ {
if (isCaretVisible())
recreateCaret();
repaint();
}
void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
{
if (caretVisible != shouldCaretBeVisible)
{ {
setCaretVisible (false);
setCaretVisible (true);
caretVisible = shouldCaretBeVisible;
recreateCaret();
} }
} }
void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
void TextEditor::recreateCaret()
{ {
if (shouldCaretBeVisible && ! isReadOnly())
if (isCaretVisible())
{ {
if (caret == nullptr) if (caret == nullptr)
{ {
@@ -1139,8 +1147,7 @@ void TextEditor::setInputFilter (InputFilter* newFilter, bool takeOwnership)
inputFilter.set (newFilter, 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); setInputFilter (new LengthAndCharacterRestriction (maxLen, chars), true);
} }
@@ -1570,7 +1577,7 @@ void TextEditor::cut()
if (! isReadOnly()) if (! isReadOnly())
{ {
moveCaret (selection.getEnd()); 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) void TextEditor::setTemporaryUnderlining (const Array<Range<int> >& newUnderlinedSections)
{ {
underlinedSections = newUnderlinedSections; underlinedSections = newUnderlinedSections;
@@ -2361,7 +2362,7 @@ String TextEditor::getText() const
String TextEditor::getTextInRange (const Range<int>& range) const String TextEditor::getTextInRange (const Range<int>& range) const
{ {
if (range.isEmpty()) if (range.isEmpty())
return String::empty;
return String();
MemoryOutputStream mo; MemoryOutputStream mo;
mo.preallocate ((size_t) jmin (getTotalNumChars(), range.getLength())); mo.preallocate ((size_t) jmin (getTotalNumChars(), range.getLength()));


+ 19
- 18
modules/juce_gui_basics/widgets/juce_TextEditor.h View File

@@ -51,7 +51,7 @@ public:
for a black splodge (not all fonts include this, though), or 0x2022, for a black splodge (not all fonts include this, though), or 0x2022,
which is a bullet (probably the best choice for linux). 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); juce_wchar passwordCharacter = 0);
/** Destructor. */ /** Destructor. */
@@ -123,7 +123,7 @@ public:
void setReadOnly (bool shouldBeReadOnly); void setReadOnly (bool shouldBeReadOnly);
/** Returns true if the editor is in read-only mode. */ /** Returns true if the editor is in read-only mode. */
bool isReadOnly() const;
bool isReadOnly() const noexcept;
//============================================================================== //==============================================================================
/** Makes the caret visible or invisible. /** Makes the caret visible or invisible.
@@ -135,7 +135,7 @@ public:
/** Returns true if the caret is enabled. /** Returns true if the caret is enabled.
@see setCaretVisible @see setCaretVisible
*/ */
bool isCaretVisible() const noexcept { return caret != nullptr; }
bool isCaretVisible() const noexcept { return caretVisible && ! isReadOnly(); }
//============================================================================== //==============================================================================
/** Enables/disables a vertical scrollbar. /** Enables/disables a vertical scrollbar.
@@ -347,7 +347,7 @@ public:
this string, otherwise it will be inserted. this string, otherwise it will be inserted.
To delete a section of text, you can use setHighlightedRegion() to 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 @see setCaretPosition, getCaretPosition, setHighlightedRegion
*/ */
@@ -583,7 +583,7 @@ public:
this string are allowed to be entered into the editor. this string are allowed to be entered into the editor.
*/ */
void setInputRestrictions (int maxTextLength, void setInputRestrictions (int maxTextLength,
const String& allowedCharacters = String::empty);
const String& allowedCharacters = String());
void setKeyboardType (VirtualKeyboardType type) noexcept { keyboardType = type; } void setKeyboardType (VirtualKeyboardType type) noexcept { keyboardType = type; }
@@ -670,19 +670,20 @@ private:
TextHolderComponent* textHolder; TextHolderComponent* textHolder;
BorderSize<int> borderSize; 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; UndoManager undoManager;
ScopedPointer<CaretComponent> caret; ScopedPointer<CaretComponent> caret;


Loading…
Cancel
Save