]> git.saurik.com Git - wxWidgets.git/commitdiff
Context menu now created in constructor; old context menu deleted when new one set.
authorJulian Smart <julian@anthemion.co.uk>
Tue, 29 Sep 2009 06:45:36 +0000 (06:45 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 29 Sep 2009 06:45:36 +0000 (06:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/richtext/richtextctrl.h
src/richtext/richtextctrl.cpp

index dc240371cb9e5b94c2dbc83c4bb927825db30c58..8d72b3909ca2b8ec04cb8cfcb6cda947d9bc44d8 100644 (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.
index 622a4ef50271e3e6f78c4cdf5db4bebf3b5f9a15..9c55ab02fbe022d08ccadf35834c1b7fd903b793 100644 (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;
 }