summaryrefslogtreecommitdiff
path: root/wx+/focus.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2018-09-09 18:53:23 -0400
committerB Stack <bgstack15@gmail.com>2018-09-09 18:53:23 -0400
commiteb5d3e5df99de2c3d8da2e8bc7b12ed427465dba (patch)
tree0f0441755ff0e6d65e12222d4502c648bffd6a7c /wx+/focus.h
parent10.3 (diff)
downloadFreeFileSync-eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba.tar.gz
FreeFileSync-eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba.tar.bz2
FreeFileSync-eb5d3e5df99de2c3d8da2e8bc7b12ed427465dba.zip
pull in latest 10.4 from upstream
Diffstat (limited to 'wx+/focus.h')
-rwxr-xr-xwx+/focus.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/wx+/focus.h b/wx+/focus.h
index cd99d010..e2daef79 100755
--- a/wx+/focus.h
+++ b/wx+/focus.h
@@ -44,22 +44,37 @@ Preserving input focus has to be more clever than:
*/
struct FocusPreserver
{
+ FocusPreserver()
+ {
+ if (wxWindow* win = wxWindow::FindFocus())
+ setFocus(win);
+ }
+
~FocusPreserver()
{
//wxTopLevelWindow::IsActive() does NOT call Win32 ::GetActiveWindow()!
//Instead it checks if ::GetFocus() is set somewhere inside the top level
//Note: Both Win32 active and focus windows are *thread-local* values, while foreground window is global! https://blogs.msdn.microsoft.com/oldnewthing/20131016-00/?p=2913
- if (oldFocus_)
- if (wxTopLevelWindow* topWin = getTopLevelWindow(oldFocus_))
- if (topWin->IsActive()) //Linux/macOS: already behaves just like ::GetForegroundWindow() on Windows!
- oldFocus_->SetFocus();
+
+ if (oldFocusId_ != wxID_ANY)
+ if (wxWindow* oldFocusWin = wxWindow::FindWindowById(oldFocusId_))
+ if (wxTopLevelWindow* topWin = getTopLevelWindow(oldFocusWin))
+ if (topWin->IsActive()) //Linux/macOS: already behaves just like ::GetForegroundWindow() on Windows!
+ oldFocusWin->SetFocus();
}
- wxWindow* getFocus() const { return oldFocus_; }
- void setFocus(wxWindow* win) { oldFocus_ = win; }
+ wxWindowID getFocusId() const { return oldFocusId_; }
+
+ void setFocus(wxWindow* win)
+ {
+ oldFocusId_ = win->GetId();
+ assert(oldFocusId_ != wxID_ANY);
+ }
private:
- wxWindow* oldFocus_ = wxWindow::FindFocus();
+ wxWindowID oldFocusId_ = wxID_ANY;
+ //don't store wxWindow* which may be dangling during ~FocusPreserver()!
+ //test: click on delete folder pair and immediately press F5 => focus window (= FP del button) is defer-deleted during sync
};
}
bgstack15