From 6e964148946e0d3772be66e31679a99282f4b271 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 29 Apr 2000 05:17:21 +0000 Subject: [PATCH] More STC fixes. Calltips and AutoComplete work now. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7314 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/stc/stc.h | 3 ++- contrib/src/stc/PlatWX.cpp | 7 ++++++- contrib/src/stc/ScintillaWX.cpp | 31 ++++++++++++++++++++++++++++++- contrib/src/stc/ScintillaWX.h | 1 + contrib/src/stc/stc.cpp | 6 ++++++ include/wx/stc/stc.h | 3 ++- src/stc/PlatWX.cpp | 7 ++++++- src/stc/ScintillaWX.cpp | 31 ++++++++++++++++++++++++++++++- src/stc/ScintillaWX.h | 1 + src/stc/stc.cpp | 6 ++++++ 10 files changed, 90 insertions(+), 6 deletions(-) diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index 7c70f14121..f2a514524e 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -492,6 +492,7 @@ private: void OnSysColourChanged(wxSysColourChangedEvent& evt); void OnEraseBackground(wxEraseEvent& evt); void OnMenu(wxCommandEvent& evt); + void OnListBox(wxCommandEvent& evt); // Turn notifications from Scintilla into events @@ -612,7 +613,7 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, -#define EVT_STC_CMDKEY(id, fn) { wxEVT_STC_CMDKEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_KEY(id, fn) { wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, diff --git a/contrib/src/stc/PlatWX.cpp b/contrib/src/stc/PlatWX.cpp index 26dc8f7c35..309f36a212 100644 --- a/contrib/src/stc/PlatWX.cpp +++ b/contrib/src/stc/PlatWX.cpp @@ -485,7 +485,12 @@ int ListBox::GetSelection() { } int ListBox::Find(const char *prefix) { - return ((wxListBox*)id)->FindString(prefix); + for (int x=0; x < ((wxListBox*)id)->Number(); x++) { + wxString text = ((wxListBox*)id)->GetString(x); + if (text.StartsWith(prefix)) + return x; + } + return -1; } void ListBox::GetValue(int n, char *value, int len) { diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index 82f784bb71..56ac221558 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -62,6 +62,29 @@ void wxSTCDropTarget::OnLeave() { } +class wxSTCCallTip : public wxWindow { +public: + wxSTCCallTip(wxWindow* parent, int ID, CallTip* ct) + : wxWindow(parent, ID) + { + m_ct = ct; + } + + void OnPaint(wxPaintEvent& evt) { + wxPaintDC dc(this); + Surface surfaceWindow; + surfaceWindow.Init(&dc); + m_ct->PaintCT(&surfaceWindow); + surfaceWindow.Release(); + } + + CallTip* m_ct; + DECLARE_EVENT_TABLE() +}; + +BEGIN_EVENT_TABLE(wxSTCCallTip, wxWindow) + EVT_PAINT(wxSTCCallTip::OnPaint) +END_EVENT_TABLE() //---------------------------------------------------------------------- // Constructor/Destructor @@ -237,7 +260,7 @@ bool ScintillaWX::CanPaste() { } void ScintillaWX::CreateCallTipWindow(PRectangle) { - ct.wCallTip = new wxWindow(wDraw.GetID(), -1); + ct.wCallTip = new wxSTCCallTip(wDraw.GetID(), -1, &ct); ct.wDraw = ct.wCallTip; } @@ -385,7 +408,10 @@ void ScintillaWX::DoButtonMove(Point pt) { void ScintillaWX::DoAddChar(char ch) { + //bool acActiveBeforeCharAdded = ac.Active(); AddChar(ch); + //if (acActiveBeforeCharAdded) + // AutoCompleteChanged(ch); } int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt) { @@ -402,6 +428,9 @@ void ScintillaWX::DoContextMenu(Point pt) { ContextMenu(pt); } +void ScintillaWX::DoOnListBox() { + AutoCompleteCompleted(); +} //---------------------------------------------------------------------- diff --git a/contrib/src/stc/ScintillaWX.h b/contrib/src/stc/ScintillaWX.h index b493b636b8..c2087c9682 100644 --- a/contrib/src/stc/ScintillaWX.h +++ b/contrib/src/stc/ScintillaWX.h @@ -126,6 +126,7 @@ public: void DoCommand(int ID); void DoContextMenu(Point pt); + void DoOnListBox(); // helpers diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index 9a891f8fa8..3ec0fb0b52 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -81,6 +81,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu) + EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) END_EVENT_TABLE() @@ -1452,6 +1453,11 @@ void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { } +void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { + m_swx->DoOnListBox(); +} + + //---------------------------------------------------------------------- // Turn notifications from Scintilla into events diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 7c70f14121..f2a514524e 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -492,6 +492,7 @@ private: void OnSysColourChanged(wxSysColourChangedEvent& evt); void OnEraseBackground(wxEraseEvent& evt); void OnMenu(wxCommandEvent& evt); + void OnListBox(wxCommandEvent& evt); // Turn notifications from Scintilla into events @@ -612,7 +613,7 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, -#define EVT_STC_CMDKEY(id, fn) { wxEVT_STC_CMDKEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_KEY(id, fn) { wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 26dc8f7c35..309f36a212 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -485,7 +485,12 @@ int ListBox::GetSelection() { } int ListBox::Find(const char *prefix) { - return ((wxListBox*)id)->FindString(prefix); + for (int x=0; x < ((wxListBox*)id)->Number(); x++) { + wxString text = ((wxListBox*)id)->GetString(x); + if (text.StartsWith(prefix)) + return x; + } + return -1; } void ListBox::GetValue(int n, char *value, int len) { diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 82f784bb71..56ac221558 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -62,6 +62,29 @@ void wxSTCDropTarget::OnLeave() { } +class wxSTCCallTip : public wxWindow { +public: + wxSTCCallTip(wxWindow* parent, int ID, CallTip* ct) + : wxWindow(parent, ID) + { + m_ct = ct; + } + + void OnPaint(wxPaintEvent& evt) { + wxPaintDC dc(this); + Surface surfaceWindow; + surfaceWindow.Init(&dc); + m_ct->PaintCT(&surfaceWindow); + surfaceWindow.Release(); + } + + CallTip* m_ct; + DECLARE_EVENT_TABLE() +}; + +BEGIN_EVENT_TABLE(wxSTCCallTip, wxWindow) + EVT_PAINT(wxSTCCallTip::OnPaint) +END_EVENT_TABLE() //---------------------------------------------------------------------- // Constructor/Destructor @@ -237,7 +260,7 @@ bool ScintillaWX::CanPaste() { } void ScintillaWX::CreateCallTipWindow(PRectangle) { - ct.wCallTip = new wxWindow(wDraw.GetID(), -1); + ct.wCallTip = new wxSTCCallTip(wDraw.GetID(), -1, &ct); ct.wDraw = ct.wCallTip; } @@ -385,7 +408,10 @@ void ScintillaWX::DoButtonMove(Point pt) { void ScintillaWX::DoAddChar(char ch) { + //bool acActiveBeforeCharAdded = ac.Active(); AddChar(ch); + //if (acActiveBeforeCharAdded) + // AutoCompleteChanged(ch); } int ScintillaWX::DoKeyDown(int key, bool shift, bool ctrl, bool alt) { @@ -402,6 +428,9 @@ void ScintillaWX::DoContextMenu(Point pt) { ContextMenu(pt); } +void ScintillaWX::DoOnListBox() { + AutoCompleteCompleted(); +} //---------------------------------------------------------------------- diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index b493b636b8..c2087c9682 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -126,6 +126,7 @@ public: void DoCommand(int ID); void DoContextMenu(Point pt); + void DoOnListBox(); // helpers diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 9a891f8fa8..3ec0fb0b52 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -81,6 +81,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu) + EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) END_EVENT_TABLE() @@ -1452,6 +1453,11 @@ void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { } +void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { + m_swx->DoOnListBox(); +} + + //---------------------------------------------------------------------- // Turn notifications from Scintilla into events