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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user