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.
This commit is contained in:
New Pagodi
2019-03-10 19:08:13 -05:00
parent 518cdc5790
commit 79e16c78bc
2 changed files with 49 additions and 5 deletions

View File

@@ -131,6 +131,7 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
// stc // stc
EVT_STC_MARGINCLICK (wxID_ANY, Edit::OnMarginClick) EVT_STC_MARGINCLICK (wxID_ANY, Edit::OnMarginClick)
EVT_STC_CHARADDED (wxID_ANY, Edit::OnCharAdded) EVT_STC_CHARADDED (wxID_ANY, Edit::OnCharAdded)
EVT_STC_CALLTIP_CLICK(wxID_ANY, Edit::OnCallTipClick)
EVT_KEY_DOWN( Edit::OnKeyDown ) EVT_KEY_DOWN( Edit::OnKeyDown )
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
@@ -189,6 +190,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id,
wxBitmap bmp(hashtag_xpm); wxBitmap bmp(hashtag_xpm);
RegisterImage(0, bmp); RegisterImage(0, bmp);
//call tips
CallTipSetBackground(*wxYELLOW);
m_calltipNo = 1;
// miscellaneous // miscellaneous
m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999"); m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999");
m_FoldingMargin = 16; m_FoldingMargin = 16;
@@ -231,11 +236,9 @@ void Edit::OnKeyDown (wxKeyEvent &event)
CallTipCancel(); CallTipCancel();
if (event.GetKeyCode() == WXK_SPACE && event.ControlDown() && event.ShiftDown()) if (event.GetKeyCode() == WXK_SPACE && event.ControlDown() && event.ShiftDown())
{ {
int pos = GetCurrentPos(); // Show our first call tip at the current position of the caret.
CallTipSetBackground(*wxYELLOW); m_calltipNo = 1;
CallTipShow(pos, ShowCallTipAt(GetCurrentPos());
"This is a CallTip with multiple lines.\n"
"It is meant to be a context sensitive popup helper for the user.");
return; return;
} }
event.Skip(); 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 // 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) { wxString Edit::DeterminePrefs (const wxString &filename) {
LanguageInfo const* curInfo; LanguageInfo const* curInfo;

View File

@@ -105,9 +105,13 @@ public:
// stc // stc
void OnMarginClick (wxStyledTextEvent &event); void OnMarginClick (wxStyledTextEvent &event);
void OnCharAdded (wxStyledTextEvent &event); void OnCharAdded (wxStyledTextEvent &event);
void OnCallTipClick(wxStyledTextEvent &event);
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
// call tips
void ShowCallTipAt(int position);
//! language/lexer //! language/lexer
wxString DeterminePrefs (const wxString &filename); wxString DeterminePrefs (const wxString &filename);
bool InitializePrefs (const wxString &filename); bool InitializePrefs (const wxString &filename);
@@ -137,6 +141,9 @@ private:
int m_FoldingMargin; int m_FoldingMargin;
int m_DividerID; int m_DividerID;
// call tip data
int m_calltipNo;
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };