From 79e16c78bc9e7d42adc6f6a7df34a29df07f36fa Mon Sep 17 00:00:00 2001 From: New Pagodi Date: Sun, 10 Mar 2019 19:08:13 -0500 Subject: [PATCH] Demonstrate call tip clicks in the stc sample This adds a demonstration of handling call tip clicks to the stc sample. Instead of showing a single call tip, 3 different call tips can be shown. The sample demonstrates how to move between the call tips depending on if the up or down button was clicked in the call tip window. --- samples/stc/edit.cpp | 47 +++++++++++++++++++++++++++++++++++++++----- samples/stc/edit.h | 7 +++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp index 335cbeccae..bd2bfd6fb3 100644 --- a/samples/stc/edit.cpp +++ b/samples/stc/edit.cpp @@ -131,6 +131,7 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl) // stc EVT_STC_MARGINCLICK (wxID_ANY, Edit::OnMarginClick) EVT_STC_CHARADDED (wxID_ANY, Edit::OnCharAdded) + EVT_STC_CALLTIP_CLICK(wxID_ANY, Edit::OnCallTipClick) EVT_KEY_DOWN( Edit::OnKeyDown ) wxEND_EVENT_TABLE() @@ -189,6 +190,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id, wxBitmap bmp(hashtag_xpm); RegisterImage(0, bmp); + //call tips + CallTipSetBackground(*wxYELLOW); + m_calltipNo = 1; + // miscellaneous m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999"); m_FoldingMargin = 16; @@ -231,11 +236,9 @@ void Edit::OnKeyDown (wxKeyEvent &event) CallTipCancel(); if (event.GetKeyCode() == WXK_SPACE && event.ControlDown() && event.ShiftDown()) { - int pos = GetCurrentPos(); - CallTipSetBackground(*wxYELLOW); - CallTipShow(pos, - "This is a CallTip with multiple lines.\n" - "It is meant to be a context sensitive popup helper for the user."); + // Show our first call tip at the current position of the caret. + m_calltipNo = 1; + ShowCallTipAt(GetCurrentPos()); return; } event.Skip(); @@ -508,9 +511,43 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) { } } +void Edit::OnCallTipClick(wxStyledTextEvent &event) +{ + if ( event.GetPosition() == 1 ) { + // If position=1, the up arrow has been clicked. Show the next tip. + m_calltipNo = m_calltipNo==3?1:(m_calltipNo+1); + ShowCallTipAt(CallTipPosAtStart()); + } + else if ( event.GetPosition() == 2 ) { + // If position=2, the down arrow has been clicked. Show previous tip. + m_calltipNo = m_calltipNo==1?3:(m_calltipNo-1); + ShowCallTipAt(CallTipPosAtStart()); + } +} + //---------------------------------------------------------------------------- // private functions +void Edit::ShowCallTipAt(int position) +{ + // In a call tip string, the character '\001' will become a clickable + // up arrow and '\002' will become a clickable down arrow. + wxString ctString = wxString::Format("\001 %d of 3 \002 ", m_calltipNo); + if ( m_calltipNo == 1 ) + ctString += "This is a call tip. Try clicking the up or down buttons."; + else if ( m_calltipNo == 2 ) + ctString += "It is meant to be a context sensitive popup helper for " + "the user."; + else + ctString += "This is a call tip with multiple lines.\n" + "You can provide slightly longer help with " + "call tips like these."; + + if ( CallTipActive() ) + CallTipCancel(); + CallTipShow(position, ctString); +} + wxString Edit::DeterminePrefs (const wxString &filename) { LanguageInfo const* curInfo; diff --git a/samples/stc/edit.h b/samples/stc/edit.h index 703ebae395..09ca020847 100644 --- a/samples/stc/edit.h +++ b/samples/stc/edit.h @@ -105,9 +105,13 @@ public: // stc void OnMarginClick (wxStyledTextEvent &event); void OnCharAdded (wxStyledTextEvent &event); + void OnCallTipClick(wxStyledTextEvent &event); void OnKeyDown(wxKeyEvent &event); + // call tips + void ShowCallTipAt(int position); + //! language/lexer wxString DeterminePrefs (const wxString &filename); bool InitializePrefs (const wxString &filename); @@ -137,6 +141,9 @@ private: int m_FoldingMargin; int m_DividerID; + // call tip data + int m_calltipNo; + wxDECLARE_EVENT_TABLE(); };