From b0d0494ff5a441a73a1d5ec80148777c19df7201 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 23 Sep 2003 23:42:41 +0000 Subject: [PATCH] Fixes in focus handling related to the AutoComplete window. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23865 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/src/stc/PlatWX.cpp | 12 +++++++++++- contrib/src/stc/ScintillaWX.cpp | 17 +++++++++++++++++ contrib/src/stc/ScintillaWX.h | 2 ++ src/stc/PlatWX.cpp | 12 +++++++++++- src/stc/ScintillaWX.cpp | 17 +++++++++++++++++ src/stc/ScintillaWX.h | 2 ++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/contrib/src/stc/PlatWX.cpp b/contrib/src/stc/PlatWX.cpp index db2960ad5b..4de8021ab3 100644 --- a/contrib/src/stc/PlatWX.cpp +++ b/contrib/src/stc/PlatWX.cpp @@ -698,7 +698,7 @@ void Window::SetTitle(const char *s) { // Helper classes for ListBox -// This is a simple subclass of wxLIstView that just resets focus to the +// This is a simple subclass of wxListView that just resets focus to the // parent when it gets it. class wxSTCListBox : public wxListView { public: @@ -713,12 +713,17 @@ public: event.Skip(); } + void OnKillFocus(wxFocusEvent& event) { + // Do nothing. Prevents base class from resetting the colors... + } + private: DECLARE_EVENT_TABLE() }; BEGIN_EVENT_TABLE(wxSTCListBox, wxListView) EVT_SET_FOCUS( wxSTCListBox::OnFocus) + EVT_KILL_FOCUS(wxSTCListBox::OnKillFocus) END_EVENT_TABLE() @@ -741,6 +746,11 @@ public: lv->SetCursor(wxCursor(wxCURSOR_ARROW)); lv->InsertColumn(0, wxEmptyString); lv->InsertColumn(1, wxEmptyString); + + // Eventhough we immediately reset the focus to the parent, this helps + // things to look right... + lv->SetFocus(); + Hide(); } diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index 73fd2d1f75..6acb7805d1 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -136,6 +136,7 @@ END_EVENT_TABLE() ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { capturedMouse = false; + focusEvent = false; wMain = win; stc = win; wheelRotation = 0; @@ -333,6 +334,18 @@ void ScintillaWX::NotifyParent(SCNotification scn) { } +// This method is overloaded from ScintillaBase in order to prevent the +// AutoComplete window from being destroyed when it gets the focus. There is +// a side effect that the AutoComp will also not be destroyed when switching +// to another window, but I think that is okay. +void ScintillaWX::CancelModes() { + if (! focusEvent) + AutoCompleteCancel(); + ct.CallTipCancel(); + Editor::CancelModes(); +} + + void ScintillaWX::Copy() { if (currentPos != anchor) { @@ -606,11 +619,15 @@ void ScintillaWX::DoSize(int WXUNUSED(width), int WXUNUSED(height)) { } void ScintillaWX::DoLoseFocus(){ + focusEvent = true; SetFocusState(false); + focusEvent = false; } void ScintillaWX::DoGainFocus(){ + focusEvent = true; SetFocusState(true); + focusEvent = false; } void ScintillaWX::DoSysColourChange() { diff --git a/contrib/src/stc/ScintillaWX.h b/contrib/src/stc/ScintillaWX.h index 2a6c5b5dbd..d0d383d507 100644 --- a/contrib/src/stc/ScintillaWX.h +++ b/contrib/src/stc/ScintillaWX.h @@ -124,6 +124,7 @@ public: virtual void NotifyChange(); virtual void NotifyParent(SCNotification scn); + virtual void CancelModes(); // Event delegates void DoPaint(wxDC* dc, wxRect rect); @@ -164,6 +165,7 @@ public: private: bool capturedMouse; + bool focusEvent; wxStyledTextCtrl* stc; #if wxUSE_DRAG_AND_DROP diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index db2960ad5b..4de8021ab3 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -698,7 +698,7 @@ void Window::SetTitle(const char *s) { // Helper classes for ListBox -// This is a simple subclass of wxLIstView that just resets focus to the +// This is a simple subclass of wxListView that just resets focus to the // parent when it gets it. class wxSTCListBox : public wxListView { public: @@ -713,12 +713,17 @@ public: event.Skip(); } + void OnKillFocus(wxFocusEvent& event) { + // Do nothing. Prevents base class from resetting the colors... + } + private: DECLARE_EVENT_TABLE() }; BEGIN_EVENT_TABLE(wxSTCListBox, wxListView) EVT_SET_FOCUS( wxSTCListBox::OnFocus) + EVT_KILL_FOCUS(wxSTCListBox::OnKillFocus) END_EVENT_TABLE() @@ -741,6 +746,11 @@ public: lv->SetCursor(wxCursor(wxCURSOR_ARROW)); lv->InsertColumn(0, wxEmptyString); lv->InsertColumn(1, wxEmptyString); + + // Eventhough we immediately reset the focus to the parent, this helps + // things to look right... + lv->SetFocus(); + Hide(); } diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 73fd2d1f75..6acb7805d1 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -136,6 +136,7 @@ END_EVENT_TABLE() ScintillaWX::ScintillaWX(wxStyledTextCtrl* win) { capturedMouse = false; + focusEvent = false; wMain = win; stc = win; wheelRotation = 0; @@ -333,6 +334,18 @@ void ScintillaWX::NotifyParent(SCNotification scn) { } +// This method is overloaded from ScintillaBase in order to prevent the +// AutoComplete window from being destroyed when it gets the focus. There is +// a side effect that the AutoComp will also not be destroyed when switching +// to another window, but I think that is okay. +void ScintillaWX::CancelModes() { + if (! focusEvent) + AutoCompleteCancel(); + ct.CallTipCancel(); + Editor::CancelModes(); +} + + void ScintillaWX::Copy() { if (currentPos != anchor) { @@ -606,11 +619,15 @@ void ScintillaWX::DoSize(int WXUNUSED(width), int WXUNUSED(height)) { } void ScintillaWX::DoLoseFocus(){ + focusEvent = true; SetFocusState(false); + focusEvent = false; } void ScintillaWX::DoGainFocus(){ + focusEvent = true; SetFocusState(true); + focusEvent = false; } void ScintillaWX::DoSysColourChange() { diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index 2a6c5b5dbd..d0d383d507 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -124,6 +124,7 @@ public: virtual void NotifyChange(); virtual void NotifyParent(SCNotification scn); + virtual void CancelModes(); // Event delegates void DoPaint(wxDC* dc, wxRect rect); @@ -164,6 +165,7 @@ public: private: bool capturedMouse; + bool focusEvent; wxStyledTextCtrl* stc; #if wxUSE_DRAG_AND_DROP -- 2.47.2