Context menu now created in constructor; old context menu deleted when new one set.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2009-09-29 06:45:36 +00:00
parent c06de7d4c8
commit 8e43fc7776
2 changed files with 21 additions and 15 deletions

View File

@ -177,7 +177,7 @@ public:
/// Get/set context menu
wxMenu* GetContextMenu() const { return m_contextMenu; }
void SetContextMenu(wxMenu* menu) { m_contextMenu = menu; }
void SetContextMenu(wxMenu* menu);
/// Anchor so we know how to extend the selection
/// It's a caret position since it's between two characters.

View File

@ -289,6 +289,17 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& va
wxAcceleratorTable accel(6, entries);
SetAcceleratorTable(accel);
m_contextMenu = new wxMenu;
m_contextMenu->Append(wxID_UNDO, _("&Undo"));
m_contextMenu->Append(wxID_REDO, _("&Redo"));
m_contextMenu->AppendSeparator();
m_contextMenu->Append(wxID_CUT, _("Cu&t"));
m_contextMenu->Append(wxID_COPY, _("&Copy"));
m_contextMenu->Append(wxID_PASTE, _("&Paste"));
m_contextMenu->Append(wxID_CLEAR, _("&Delete"));
m_contextMenu->AppendSeparator();
m_contextMenu->Append(wxID_SELECTALL, _("Select &All"));
return true;
}
@ -2504,6 +2515,13 @@ bool wxRichTextCtrl::CanDeleteSelection() const
// Accessors
// ----------------------------------------------------------------------------
void wxRichTextCtrl::SetContextMenu(wxMenu* menu)
{
if (m_contextMenu && m_contextMenu != menu)
delete m_contextMenu;
m_contextMenu = menu;
}
void wxRichTextCtrl::SetEditable(bool editable)
{
m_editable = editable;
@ -2803,20 +2821,8 @@ void wxRichTextCtrl::OnContextMenu(wxContextMenuEvent& event)
return;
}
if (!m_contextMenu)
{
m_contextMenu = new wxMenu;
m_contextMenu->Append(wxID_UNDO, _("&Undo"));
m_contextMenu->Append(wxID_REDO, _("&Redo"));
m_contextMenu->AppendSeparator();
m_contextMenu->Append(wxID_CUT, _("Cu&t"));
m_contextMenu->Append(wxID_COPY, _("&Copy"));
m_contextMenu->Append(wxID_PASTE, _("&Paste"));
m_contextMenu->Append(wxID_CLEAR, _("&Delete"));
m_contextMenu->AppendSeparator();
m_contextMenu->Append(wxID_SELECTALL, _("Select &All"));
}
PopupMenu(m_contextMenu);
if (m_contextMenu)
PopupMenu(m_contextMenu);
return;
}