1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-26 02:14:22 +00:00

AlertWindow: ensure a native keyboard is hidden when alert window gets dismissed.

This commit is contained in:
Lukasz Kozakiewicz 2018-04-09 18:35:37 +02:00
parent da0792c784
commit c8b9bc79ba
3 changed files with 27 additions and 5 deletions

View file

@ -1240,6 +1240,16 @@ void TextEditor::removeListener (Listener* l) { listeners.remove (l); }
//==============================================================================
void TextEditor::timerCallbackInt()
{
checkFocus();
auto now = Time::getApproximateMillisecondCounter();
if (now > lastTransactionTime + 200)
newTransaction();
}
void TextEditor::checkFocus()
{
if (hasKeyboardFocus (false) && ! isCurrentlyBlockedByAnotherModalComponent())
{
@ -1249,11 +1259,6 @@ void TextEditor::timerCallbackInt()
if (! isReadOnly())
peer->textInputRequired (peer->globalToLocal (getScreenPosition()), *this);
}
auto now = Time::getApproximateMillisecondCounter();
if (now > lastTransactionTime + 200)
newTransaction();
}
void TextEditor::repaintText (Range<int> range)
@ -2066,6 +2071,12 @@ void TextEditor::focusGained (FocusChangeType)
moveCaretTo (getTotalNumChars(), true);
}
// When caret position changes, we check focus automatically, to
// show any native keyboard if needed. If the position does not
// change though, we need to check focus manually.
if (getTotalNumChars() == 0)
checkFocus();
repaint();
updateCaretPosition();
}

View file

@ -777,6 +777,7 @@ private:
float getWordWrapWidth() const;
float getJustificationWidth() const;
void timerCallbackInt();
void checkFocus();
void repaintText (Range<int>);
void scrollByLines (int deltaLines);
bool undoOrRedo (bool shouldUndo);

View file

@ -58,6 +58,16 @@ AlertWindow::AlertWindow (const String& title,
AlertWindow::~AlertWindow()
{
// Ensure that the focus does not jump to another TextEditor while we
// remove children.
for (auto* t : textBoxes)
t->setWantsKeyboardFocus (false);
// Giveaway focus before removing the editors, so that any TextEditor
// with focus has a chance to dismiss native keyboard if shown.
if (hasKeyboardFocus (true))
Component::unfocusAllComponents();
removeAllChildren();
}