lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 49ce3c0 3/3: Fix defect introduced 20160528T0


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 49ce3c0 3/3: Fix defect introduced 20160528T0114Z: focus check not updated (VZ)
Date: Thu, 16 Feb 2017 06:38:29 -0500 (EST)

branch: master
commit 49ce3c03d0af4b7570b08a250ecbf8c305be6da7
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Fix defect introduced 20160528T0114Z: focus check not updated (VZ)
    
    The code checking whether focus remains inside the same
    InputSequenceEntry wasn't updated after refactoring of
      88f6e9d4aa30b49509fc108dbb269e8718e4cd28
      AuthorDate: 2015-11-19 01:38:00 +0100
      CommitDate: 2016-05-28 01:14:35 +0000
    and could return wrong results, e.g. the check failed when focus
    switched to the subwindow of wxDataViewCtrl which was the parent of
    InputSequenceEntry itself and so the in-place editor wasn't closed
    in this case, allowing to open more than one editor at once, which
    is supposed to be impossible.
    
    Also inverted the check direction to make it more natural and added a
    helper is_child_of() function to make the parent checks more readable.
---
 input_sequence_entry.cpp | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/input_sequence_entry.cpp b/input_sequence_entry.cpp
index d8e2937..90ed17f 100644
--- a/input_sequence_entry.cpp
+++ b/input_sequence_entry.cpp
@@ -1492,15 +1492,27 @@ std::string InputSequenceEntry::field_name() const
 
 void InputSequenceEntry::UponChildKillFocus(wxFocusEvent& event)
 {
-    // Don't notify the parent (and thus wxDataViewCtrl) of focus change if 
its within this
-    // InputSequenceEntry composite control or a InputSequenceEditor window 
opened from it.
-    if(nullptr == event.GetWindow() ||
-        (event.GetWindow()->GetParent() != GetParent() &&
-        wxGetTopLevelParent(event.GetWindow())->GetParent() != this))
+    // Check whether the given possibly null window is a child of another one.
+    auto const is_child_of = [](wxWindow const* c, wxWindow const* p)
         {
-        GetParent()->ProcessWindowEvent(event);
+        return c && c->GetParent() == p;
+        };
+
+    // Suppress normal focus loss event processing if the focus simply goes to
+    // another element of this composite window or changes inside an
+    // InputSequenceEntry window opened from it and having our button as the
+    // parent: this prevents the in-place editor in the census view from
+    // closing whenever this happens.
+    if
+        (  is_child_of(event.GetWindow(), this)
+        || is_child_of(wxGetTopLevelParent(event.GetWindow()), button_)
+        )
+        {
+        event.Skip();
+        return;
         }
-    event.Skip();
+
+    ProcessWindowEvent(event);
 }
 
 void InputSequenceEntry::UponEnter(wxCommandEvent& event)
@@ -1539,6 +1551,8 @@ void InputSequenceEntry::DoOpenEditor()
 
     // Center the window on the [...] button for best locality -- it will be
     // close to user's point of attention and the mouse cursor.
+    // Note that if the parent used here changes, the code in
+    // UponChildKillFocus() would need to be updated.
     InputSequenceEditor editor(button_, title_, in);
 
     std::string sequence_string = std::string(text_->GetValue());



reply via email to

[Prev in Thread] Current Thread [Next in Thread]