Add option to display custom context menu in stc sample
This option could be useful to demonstrate ability to replace (override) standard Scintilla context menu with custom one. Switching between standard and custom popup menu is done with "Extra -> Custom popup menu" menu option.
This commit is contained in:
committed by
Artur Wieczorek
parent
6aa5d07229
commit
962979ebf1
@@ -76,6 +76,7 @@ enum {
|
|||||||
myID_MULTIPLE_SELECTIONS,
|
myID_MULTIPLE_SELECTIONS,
|
||||||
myID_MULTI_PASTE,
|
myID_MULTI_PASTE,
|
||||||
myID_MULTIPLE_SELECTIONS_TYPING,
|
myID_MULTIPLE_SELECTIONS_TYPING,
|
||||||
|
myID_CUSTOM_POPUP,
|
||||||
myID_USECHARSET,
|
myID_USECHARSET,
|
||||||
myID_CHARSETANSI,
|
myID_CHARSETANSI,
|
||||||
myID_CHARSETMAC,
|
myID_CHARSETMAC,
|
||||||
|
@@ -111,6 +111,7 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
|
|||||||
EVT_MENU(myID_MULTIPLE_SELECTIONS, Edit::OnMultipleSelections)
|
EVT_MENU(myID_MULTIPLE_SELECTIONS, Edit::OnMultipleSelections)
|
||||||
EVT_MENU(myID_MULTI_PASTE, Edit::OnMultiPaste)
|
EVT_MENU(myID_MULTI_PASTE, Edit::OnMultiPaste)
|
||||||
EVT_MENU(myID_MULTIPLE_SELECTIONS_TYPING, Edit::OnMultipleSelectionsTyping)
|
EVT_MENU(myID_MULTIPLE_SELECTIONS_TYPING, Edit::OnMultipleSelectionsTyping)
|
||||||
|
EVT_MENU(myID_CUSTOM_POPUP, Edit::OnCustomPopup)
|
||||||
// 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)
|
||||||
@@ -175,7 +176,7 @@ Edit::Edit (wxWindow *parent, wxWindowID id,
|
|||||||
m_FoldingMargin = 16;
|
m_FoldingMargin = 16;
|
||||||
CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key
|
CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key
|
||||||
SetLayoutCache (wxSTC_CACHE_PAGE);
|
SetLayoutCache (wxSTC_CACHE_PAGE);
|
||||||
|
UsePopUp(wxSTC_POPUP_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Edit::~Edit () {}
|
Edit::~Edit () {}
|
||||||
@@ -453,6 +454,11 @@ void Edit::OnMultipleSelectionsTyping(wxCommandEvent& WXUNUSED(event)) {
|
|||||||
SetAdditionalSelectionTyping(!isSet);
|
SetAdditionalSelectionTyping(!isSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Edit::OnCustomPopup(wxCommandEvent& evt)
|
||||||
|
{
|
||||||
|
UsePopUp(evt.IsChecked() ? wxSTC_POPUP_NEVER : wxSTC_POPUP_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
//! misc
|
//! misc
|
||||||
void Edit::OnMarginClick (wxStyledTextEvent &event) {
|
void Edit::OnMarginClick (wxStyledTextEvent &event) {
|
||||||
if (event.GetMargin() == 2) {
|
if (event.GetMargin() == 2) {
|
||||||
|
@@ -101,6 +101,7 @@ public:
|
|||||||
void OnMultipleSelections(wxCommandEvent& event);
|
void OnMultipleSelections(wxCommandEvent& event);
|
||||||
void OnMultiPaste(wxCommandEvent& event);
|
void OnMultiPaste(wxCommandEvent& event);
|
||||||
void OnMultipleSelectionsTyping(wxCommandEvent& event);
|
void OnMultipleSelectionsTyping(wxCommandEvent& event);
|
||||||
|
void OnCustomPopup(wxCommandEvent& evt);
|
||||||
// stc
|
// stc
|
||||||
void OnMarginClick (wxStyledTextEvent &event);
|
void OnMarginClick (wxStyledTextEvent &event);
|
||||||
void OnCharAdded (wxStyledTextEvent &event);
|
void OnCharAdded (wxStyledTextEvent &event);
|
||||||
|
@@ -146,6 +146,7 @@ public:
|
|||||||
void OnPrint (wxCommandEvent &event);
|
void OnPrint (wxCommandEvent &event);
|
||||||
//! edit events
|
//! edit events
|
||||||
void OnEdit (wxCommandEvent &event);
|
void OnEdit (wxCommandEvent &event);
|
||||||
|
void OnContextMenu(wxContextMenuEvent& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// edit object
|
// edit object
|
||||||
@@ -276,6 +277,7 @@ wxBEGIN_EVENT_TABLE (AppFrame, wxFrame)
|
|||||||
AppFrame::OnEdit)
|
AppFrame::OnEdit)
|
||||||
// help
|
// help
|
||||||
EVT_MENU (wxID_ABOUT, AppFrame::OnAbout)
|
EVT_MENU (wxID_ABOUT, AppFrame::OnAbout)
|
||||||
|
EVT_CONTEXT_MENU( AppFrame::OnContextMenu)
|
||||||
wxEND_EVENT_TABLE ()
|
wxEND_EVENT_TABLE ()
|
||||||
|
|
||||||
AppFrame::AppFrame (const wxString &title)
|
AppFrame::AppFrame (const wxString &title)
|
||||||
@@ -438,6 +440,27 @@ void AppFrame::OnEdit (wxCommandEvent &event) {
|
|||||||
if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event);
|
if (m_edit) m_edit->GetEventHandler()->ProcessEvent (event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppFrame::OnContextMenu(wxContextMenuEvent& evt)
|
||||||
|
{
|
||||||
|
wxPoint point = evt.GetPosition();
|
||||||
|
// If from keyboard
|
||||||
|
if ( point.x == -1 && point.y == -1 )
|
||||||
|
{
|
||||||
|
wxSize size = GetSize();
|
||||||
|
point.x = size.x / 2;
|
||||||
|
point.y = size.y / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
point = ScreenToClient(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxMenu menu;
|
||||||
|
menu.Append(wxID_ABOUT, wxT("&About"));
|
||||||
|
menu.Append(wxID_EXIT, wxT("E&xit"));
|
||||||
|
PopupMenu(&menu, point);
|
||||||
|
}
|
||||||
|
|
||||||
// private functions
|
// private functions
|
||||||
void AppFrame::CreateMenu ()
|
void AppFrame::CreateMenu ()
|
||||||
{
|
{
|
||||||
@@ -549,6 +572,8 @@ void AppFrame::CreateMenu ()
|
|||||||
menuExtra->AppendCheckItem(myID_MULTIPLE_SELECTIONS, _("Toggle &multiple selections"));
|
menuExtra->AppendCheckItem(myID_MULTIPLE_SELECTIONS, _("Toggle &multiple selections"));
|
||||||
menuExtra->AppendCheckItem(myID_MULTI_PASTE, _("Toggle multi-&paste"));
|
menuExtra->AppendCheckItem(myID_MULTI_PASTE, _("Toggle multi-&paste"));
|
||||||
menuExtra->AppendCheckItem(myID_MULTIPLE_SELECTIONS_TYPING, _("Toggle t&yping on multiple selections"));
|
menuExtra->AppendCheckItem(myID_MULTIPLE_SELECTIONS_TYPING, _("Toggle t&yping on multiple selections"));
|
||||||
|
menuExtra->AppendSeparator();
|
||||||
|
menuExtra->AppendCheckItem (myID_CUSTOM_POPUP, _("C&ustom popup menu"));
|
||||||
|
|
||||||
// Window menu
|
// Window menu
|
||||||
wxMenu *menuWindow = new wxMenu;
|
wxMenu *menuWindow = new wxMenu;
|
||||||
|
Reference in New Issue
Block a user