Browse Source

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

tags/2021-05-28
Lukasz Kozakiewicz 7 years ago
parent
commit
c8b9bc79ba
3 changed files with 27 additions and 5 deletions
  1. +16
    -5
      modules/juce_gui_basics/widgets/juce_TextEditor.cpp
  2. +1
    -0
      modules/juce_gui_basics/widgets/juce_TextEditor.h
  3. +10
    -0
      modules/juce_gui_basics/windows/juce_AlertWindow.cpp

+ 16
- 5
modules/juce_gui_basics/widgets/juce_TextEditor.cpp View File

@@ -1240,6 +1240,16 @@ void TextEditor::removeListener (Listener* l) { listeners.remove (l); }
//============================================================================== //==============================================================================
void TextEditor::timerCallbackInt() void TextEditor::timerCallbackInt()
{
checkFocus();
auto now = Time::getApproximateMillisecondCounter();
if (now > lastTransactionTime + 200)
newTransaction();
}
void TextEditor::checkFocus()
{ {
if (hasKeyboardFocus (false) && ! isCurrentlyBlockedByAnotherModalComponent()) if (hasKeyboardFocus (false) && ! isCurrentlyBlockedByAnotherModalComponent())
{ {
@@ -1249,11 +1259,6 @@ void TextEditor::timerCallbackInt()
if (! isReadOnly()) if (! isReadOnly())
peer->textInputRequired (peer->globalToLocal (getScreenPosition()), *this); peer->textInputRequired (peer->globalToLocal (getScreenPosition()), *this);
} }
auto now = Time::getApproximateMillisecondCounter();
if (now > lastTransactionTime + 200)
newTransaction();
} }
void TextEditor::repaintText (Range<int> range) void TextEditor::repaintText (Range<int> range)
@@ -2066,6 +2071,12 @@ void TextEditor::focusGained (FocusChangeType)
moveCaretTo (getTotalNumChars(), true); 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(); repaint();
updateCaretPosition(); updateCaretPosition();
} }


+ 1
- 0
modules/juce_gui_basics/widgets/juce_TextEditor.h View File

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


+ 10
- 0
modules/juce_gui_basics/windows/juce_AlertWindow.cpp View File

@@ -58,6 +58,16 @@ AlertWindow::AlertWindow (const String& title,
AlertWindow::~AlertWindow() 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(); removeAllChildren();
} }


Loading…
Cancel
Save