diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 53c6ab6032..3c390b1b08 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -5662,6 +5662,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_COPY, wxStyledTex wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_COMPLETED, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_MARGIN_RIGHT_CLICK, wxStyledTextEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_SELECTION_CHANGE, wxStyledTextEvent ); #else enum { @@ -5703,7 +5704,8 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_MARGIN_RIGHT_CLICK, wxStyle wxEVT_STC_CLIPBOARD_COPY, wxEVT_STC_CLIPBOARD_PASTE, wxEVT_STC_AUTOCOMP_COMPLETED, - wxEVT_STC_MARGIN_RIGHT_CLICK + wxEVT_STC_MARGIN_RIGHT_CLICK, + wxEVT_STC_AUTOCOMP_SELECTION_CHANGE }; #endif @@ -5750,7 +5752,7 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_CLIPBOARD_PASTE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CLIPBOARD_PASTE, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_AUTOCOMP_COMPLETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_COMPLETED, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_MARGIN_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_MARGIN_RIGHT_CLICK, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), - +#define EVT_STC_AUTOCOMP_SELECTION_CHANGE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_SELECTION_CHANGE, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #endif #endif // wxUSE_STC diff --git a/interface/wx/stc/stc.h b/interface/wx/stc/stc.h index 21a3a4cac4..02030c40ad 100644 --- a/interface/wx/stc/stc.h +++ b/interface/wx/stc/stc.h @@ -7876,6 +7876,10 @@ public: @event{EVT_STC_AUTOCOMP_SELECTION(id, fn)} Process a @c wxEVT_STC_AUTOCOMP_SELECTION event. + @event{EVT_STC_AUTOCOMP_SELECTION_CHANGE(id, fn)} + Process a @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE event. + @since 3.1.3 + @event{EVT_STC_CALLTIP_CLICK(id, fn)} Process a @c wxEVT_STC_CALLTIP_CLICK event. @event{EVT_STC_CHANGE(id, fn)} @@ -7996,6 +8000,27 @@ public: @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::GetListCompletionMethod GetListCompletionMethod@endlink. + @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE + + - Generated when items are highlighted in an autocompletion or user list. + + - @link wxStyledTextEvent::GetPosition GetPosition@endlink will return the + position at which the list is being shown. + + - For a user list, @link wxStyledTextEvent::GetListType GetListType@endlink + will return the list type. The list type is a value input in to the + @link wxStyledTextCtrl::UserListShow wxStyledTextCtrl::UserListShow@endlink + method when a user list is created. + + - For an autocompletion list, + @link wxStyledTextEvent::GetListType GetListType@endlink will always return + zero. + + - Valid event functions: + @link wxStyledTextEvent::GetListType GetListType@endlink, + @link wxStyledTextEvent::GetPosition GetPosition@endlink, + @link wxStyledTextEvent::GetString GetString@endlink. + @c wxEVT_STC_CALLTIP_CLICK - Generated when a calltip has been clicked. @@ -8488,7 +8513,8 @@ public: wxStyledTextCtrl::UserListShow @endlink method and can be used to distinguish lists if more than one is used. - This method is valid for @c wxEVT_STC_USERLISTSELECTION events. + This method is valid for @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE and + @c wxEVT_STC_USERLISTSELECTION events. */ int GetListType() const; @@ -8636,6 +8662,7 @@ public: - @c wxEVT_STC_INDICATOR_RELEASE - @c wxEVT_STC_CALLTIP_CLICK - @c wxEVT_STC_AUTOCOMP_SELECTION + - @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE - @c wxEVT_STC_AUTOCOMP_COMPLETED - @c wxEVT_STC_MARGIN_RIGHT_CLICK */ @@ -8889,3 +8916,4 @@ const wxEventType wxEVT_STC_CLIPBOARD_COPY; const wxEventType wxEVT_STC_CLIPBOARD_PASTE; const wxEventType wxEVT_STC_AUTOCOMP_COMPLETED; const wxEventType wxEVT_STC_MARGIN_RIGHT_CLICK; +const wxEventType wxEVT_STC_AUTOCOMP_SELECTION_CHANGE; diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 0a1289e5c6..cb51295f68 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -2562,7 +2562,7 @@ const wxColour& wxSTCListBoxVisualData::GetCurrentTextColour() const class wxSTCListBox : public wxSystemThemedControl { public: - wxSTCListBox(wxWindow*, wxSTCListBoxVisualData*, int); + wxSTCListBox(wxWindow*, wxSTCListBoxVisualData*, int, int, int*, int*); // wxWindow overrides virtual bool AcceptsFocus() const wxOVERRIDE; @@ -2587,11 +2587,13 @@ public: protected: // Helpers void AppendHelper(const wxString& text, int type); + void SelectHelper(int i); void AccountForBitmap(int type, bool recalculateItemHeight); void RecalculateItemHeight(); int TextBoxFromClientEdge() const; // Event handlers + void OnSelection(wxCommandEvent&); void OnDClick(wxCommandEvent&); void OnSysColourChanged(wxSysColourChangedEvent& event); void OnMouseMotion(wxMouseEvent& event); @@ -2614,6 +2616,9 @@ private: CallBackAction m_doubleClickAction; void* m_doubleClickActionData; int m_aveCharWidth; + int m_listType; + int* m_posStart; + int* m_startLen; // These drawing parameters are computed or set externally. int m_borderSize; @@ -2630,12 +2635,14 @@ private: int m_textExtraVerticalPadding; }; -wxSTCListBox::wxSTCListBox(wxWindow* parent, wxSTCListBoxVisualData* v, int ht) +wxSTCListBox::wxSTCListBox(wxWindow* parent, wxSTCListBoxVisualData* v, + int ht, int listType, int* posStart, int* startLen) :wxSystemThemedControl(), m_visualData(v), m_maxStrWidth(0), m_currentRow(wxNOT_FOUND), m_doubleClickAction(NULL), m_doubleClickActionData(NULL), m_aveCharWidth(8), m_textHeight(ht), m_itemHeight(ht), - m_textTopGap(0), m_imageAreaWidth(0), m_imageAreaHeight(0) + m_textTopGap(0), m_imageAreaWidth(0), m_imageAreaHeight(0), + m_listType(listType), m_posStart(posStart), m_startLen(startLen) { wxVListBox::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); @@ -2646,6 +2653,7 @@ wxSTCListBox::wxSTCListBox(wxWindow* parent, wxSTCListBoxVisualData* v, int ht) SetBackgroundColour(m_visualData->GetBgColour()); + Bind(wxEVT_LISTBOX, &wxSTCListBox::OnSelection, this); Bind(wxEVT_LISTBOX_DCLICK, &wxSTCListBox::OnDClick, this); Bind(wxEVT_SYS_COLOUR_CHANGED, &wxSTCListBox::OnSysColourChanged, this); @@ -2759,6 +2767,7 @@ int wxSTCListBox::Length() const void wxSTCListBox::Select(int n) { SetSelection(n); + SelectHelper(n); } void wxSTCListBox::GetValue(int n, char *value, int len) const @@ -2806,6 +2815,39 @@ void wxSTCListBox::AppendHelper(const wxString& text, int type) SetItemCount(m_labels.size()); } +void wxSTCListBox::SelectHelper(int i) +{ + // This method is used to trigger the wxEVT_STC_AUTOCOMP_SELECTION_CHANGE + // event. This event is generated directly here since the version of + // Scintilla currently used does not support it. + + //If the Scintilla component is updated, it should be sufficient to: + // 1) change this method to use a callback to let Scintilla generate the + // event. + // 2) remove the member variables m_listType, m_posStart, and m_startLen + // from this and the ListBoxImpl class since they will no longer be + // needed. The SetListInfo method can also be removed from ListBoxImpl. + + wxStyledTextCtrl* stc = wxDynamicCast(GetGrandParent(), wxStyledTextCtrl); + + if ( stc ) + { + wxStyledTextEvent evt(wxEVT_STC_AUTOCOMP_SELECTION_CHANGE,stc->GetId()); + evt.SetEventObject(stc); + evt.SetListType(m_listType); + + if ( m_posStart != NULL && m_startLen != NULL ) + evt.SetPosition(*m_posStart - *m_startLen); + else + evt.SetPosition(stc->AutoCompPosStart()); + + if ( 0 <= i && i < static_cast(m_labels.size()) ) + evt.SetString(m_labels[i]); + + stc->ProcessWindowEvent(evt); + } +} + void wxSTCListBox::AccountForBitmap(int type, bool recalculateItemHeight) { const int oldHeight = m_imageAreaHeight; @@ -2836,6 +2878,11 @@ int wxSTCListBox::TextBoxFromClientEdge() const return (m_imageAreaWidth == 0 ? 0 : m_imageAreaWidth + 2 * m_imagePadding); } +void wxSTCListBox::OnSelection(wxCommandEvent& event) +{ + SelectHelper(event.GetSelection()); +} + void wxSTCListBox::OnDClick(wxCommandEvent& WXUNUSED(event)) { if ( m_doubleClickAction ) @@ -3002,7 +3049,8 @@ void wxSTCListBox::OnDrawBackground(wxDC &dc, const wxRect &rect,size_t n) const class wxSTCListBoxWin : public wxSTCPopupWindow { public: - wxSTCListBoxWin(wxWindow*, wxSTCListBox**, wxSTCListBoxVisualData*, int); + wxSTCListBoxWin(wxWindow*, wxSTCListBox**, wxSTCListBoxVisualData*, + int, int, int*, int*); protected: void OnPaint(wxPaintEvent&); @@ -3012,10 +3060,11 @@ private: }; wxSTCListBoxWin::wxSTCListBoxWin(wxWindow* parent, wxSTCListBox** lb, - wxSTCListBoxVisualData* v, int h) + wxSTCListBoxVisualData* v, int h, + int t, int* p, int* l) :wxSTCPopupWindow(parent) { - *lb = new wxSTCListBox(this, v, h); + *lb = new wxSTCListBox(this, v, h, t, p, l); // Use the background of this window to form a frame around the listbox // except on macos where the native Scintilla popup has no frame. @@ -3049,7 +3098,8 @@ void wxSTCListBoxWin::OnPaint(wxPaintEvent& WXUNUSED(evt)) //---------------------------------------------------------------------- ListBoxImpl::ListBoxImpl() - :m_listBox(NULL), m_visualData(new wxSTCListBoxVisualData(5)) + :m_listBox(NULL), m_visualData(new wxSTCListBoxVisualData(5)), + m_listType(NULL), m_posStart(NULL), m_startLen(NULL) { } @@ -3068,7 +3118,8 @@ void ListBoxImpl::Create(Window &parent, int WXUNUSED(ctrlID), bool WXUNUSED(unicodeMode_), int WXUNUSED(technology_)) { wid = new wxSTCListBoxWin(GETWIN(parent.GetID()), &m_listBox, m_visualData, - lineHeight_); + lineHeight_, (m_listType?*m_listType:0), + m_posStart, m_startLen); } @@ -3163,6 +3214,13 @@ void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { m_listBox->SetDoubleClickAction(action, data); } +void ListBoxImpl::SetListInfo(int* listType, int* posStart, int* startLen) +{ + m_listType = listType; + m_posStart = posStart; + m_startLen = startLen; +} + ListBox::ListBox() { } diff --git a/src/stc/PlatWX.h b/src/stc/PlatWX.h index 52c7eb92c9..c24bd4f50e 100644 --- a/src/stc/PlatWX.h +++ b/src/stc/PlatWX.h @@ -22,6 +22,9 @@ class ListBoxImpl : public ListBox { private: wxSTCListBox* m_listBox; wxSTCListBoxVisualData* m_visualData; + int* m_listType; + int* m_posStart; + int* m_startLen; public: ListBoxImpl(); @@ -49,6 +52,7 @@ public: virtual void ClearRegisteredImages() wxOVERRIDE; virtual void SetDoubleClickAction(CallBackAction, void *) wxOVERRIDE; virtual void SetList(const char* list, char separator, char typesep) wxOVERRIDE; + void SetListInfo(int*, int*, int*); }; diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 3796bf9f9f..74c57f50ff 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -293,6 +293,9 @@ void ScintillaWX::Initialise() { kmap.AssignCmdKey(SCK_UP, SCI_CTRL, SCI_DOCUMENTSTART); kmap.AssignCmdKey(SCK_DOWN, SCI_CTRL, SCI_DOCUMENTEND); #endif // __WXMAC__ + + static_cast(ac.lb)->SetListInfo(&listType, &(ac.posStart), + &(ac.startLen)); } diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index b01802915c..789b44caf7 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -136,6 +136,7 @@ wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_COPY, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_COMPLETED, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_MARGIN_RIGHT_CLICK, wxStyledTextEvent ); +wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_SELECTION_CHANGE, wxStyledTextEvent ); wxBEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index fb44624ab7..833b8c9a33 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -136,6 +136,7 @@ wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_COPY, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_COMPLETED, wxStyledTextEvent ); wxDEFINE_EVENT( wxEVT_STC_MARGIN_RIGHT_CLICK, wxStyledTextEvent ); +wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_SELECTION_CHANGE, wxStyledTextEvent ); wxBEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 503f127c25..679c0e16e0 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -779,6 +779,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_COPY, wxStyledTex wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_CLIPBOARD_PASTE, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_COMPLETED, wxStyledTextEvent ); wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_MARGIN_RIGHT_CLICK, wxStyledTextEvent ); +wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_AUTOCOMP_SELECTION_CHANGE, wxStyledTextEvent ); #else enum { @@ -820,7 +821,8 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_STC, wxEVT_STC_MARGIN_RIGHT_CLICK, wxStyle wxEVT_STC_CLIPBOARD_COPY, wxEVT_STC_CLIPBOARD_PASTE, wxEVT_STC_AUTOCOMP_COMPLETED, - wxEVT_STC_MARGIN_RIGHT_CLICK + wxEVT_STC_MARGIN_RIGHT_CLICK, + wxEVT_STC_AUTOCOMP_SELECTION_CHANGE }; #endif @@ -867,7 +869,7 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_CLIPBOARD_PASTE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_CLIPBOARD_PASTE, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_AUTOCOMP_COMPLETED(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_COMPLETED, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #define EVT_STC_MARGIN_RIGHT_CLICK(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_MARGIN_RIGHT_CLICK, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), - +#define EVT_STC_AUTOCOMP_SELECTION_CHANGE(id, fn) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_STC_AUTOCOMP_SELECTION_CHANGE, id, wxID_ANY, wxStyledTextEventHandler( fn ), (wxObject *) NULL ), #endif #endif // wxUSE_STC diff --git a/src/stc/stc.interface.h.in b/src/stc/stc.interface.h.in index f2ac38130b..992fb32fb7 100644 --- a/src/stc/stc.interface.h.in +++ b/src/stc/stc.interface.h.in @@ -816,6 +816,10 @@ public: @event{EVT_STC_AUTOCOMP_SELECTION(id, fn)} Process a @c wxEVT_STC_AUTOCOMP_SELECTION event. + @event{EVT_STC_AUTOCOMP_SELECTION_CHANGE(id, fn)} + Process a @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE event. + @since 3.1.3 + @event{EVT_STC_CALLTIP_CLICK(id, fn)} Process a @c wxEVT_STC_CALLTIP_CLICK event. @event{EVT_STC_CHANGE(id, fn)} @@ -936,6 +940,27 @@ public: @link wxStyledTextEvent::GetString GetString@endlink, @link wxStyledTextEvent::GetListCompletionMethod GetListCompletionMethod@endlink. + @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE + + - Generated when items are highlighted in an autocompletion or user list. + + - @link wxStyledTextEvent::GetPosition GetPosition@endlink will return the + position at which the list is being shown. + + - For a user list, @link wxStyledTextEvent::GetListType GetListType@endlink + will return the list type. The list type is a value input in to the + @link wxStyledTextCtrl::UserListShow wxStyledTextCtrl::UserListShow@endlink + method when a user list is created. + + - For an autocompletion list, + @link wxStyledTextEvent::GetListType GetListType@endlink will always return + zero. + + - Valid event functions: + @link wxStyledTextEvent::GetListType GetListType@endlink, + @link wxStyledTextEvent::GetPosition GetPosition@endlink, + @link wxStyledTextEvent::GetString GetString@endlink. + @c wxEVT_STC_CALLTIP_CLICK - Generated when a calltip has been clicked. @@ -1428,7 +1453,8 @@ public: wxStyledTextCtrl::UserListShow @endlink method and can be used to distinguish lists if more than one is used. - This method is valid for @c wxEVT_STC_USERLISTSELECTION events. + This method is valid for @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE and + @c wxEVT_STC_USERLISTSELECTION events. */ int GetListType() const; @@ -1576,6 +1602,7 @@ public: - @c wxEVT_STC_INDICATOR_RELEASE - @c wxEVT_STC_CALLTIP_CLICK - @c wxEVT_STC_AUTOCOMP_SELECTION + - @c wxEVT_STC_AUTOCOMP_SELECTION_CHANGE - @c wxEVT_STC_AUTOCOMP_COMPLETED - @c wxEVT_STC_MARGIN_RIGHT_CLICK */ @@ -1829,3 +1856,4 @@ const wxEventType wxEVT_STC_CLIPBOARD_COPY; const wxEventType wxEVT_STC_CLIPBOARD_PASTE; const wxEventType wxEVT_STC_AUTOCOMP_COMPLETED; const wxEventType wxEVT_STC_MARGIN_RIGHT_CLICK; +const wxEventType wxEVT_STC_AUTOCOMP_SELECTION_CHANGE;