wxTextCtrl custom popup menu items Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Forest
Knows some wx things
Knows some wx things
Posts: 39
Joined: Fri Feb 06, 2009 3:58 pm

wxTextCtrl custom popup menu items

Post by Forest »

When you right-click on wxTextCtrl menu with Copy, Paste, etc appears.
How can I add custom items to that menu?
Sorry for lame English... :)
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

I don't think you can. At least not with wxWidgets methods, this popup is native behavior of the control.
Use the source, Luke!
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan »

Hi, here is a sample:

Code: Select all

...
class MyTextCtrl : public wxTextCtrl
{
public:
      MyTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = "",
                 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
                 long style = 0, const wxValidator& validator = wxDefaultValidator,
                 const wxString& name = wxTextCtrlNameStr)
    : wxTextCtrl(parent, id, value, pos, size, style, validator, name) {}
protected:
    void OnContextMenu(wxContextMenuEvent& event);

    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
    EVT_CONTEXT_MENU(MyTextCtrl::OnContextMenu)
END_EVENT_TABLE()

void MyTextCtrl::OnContextMenu(wxContextMenuEvent& event)
{
        wxMenu* menu = new wxMenu;
        // Some standard items
        menu->Append(wxID_UNDO, _("&Undo"));
        menu->Append(wxID_REDO, _("&Redo"));
        menu->AppendSeparator();
        menu->Append(wxID_CUT, _("Cu&t"));
        menu->Append(wxID_COPY, _("&Copy"));
        menu->Append(wxID_PASTE, _("&Paste"));
        menu->Append(wxID_CLEAR, _("&Delete"));
        menu->AppendSeparator();
        menu->Append(wxID_SELECTALL, _("Select &All"));

        // Add any custom items here

        PopupMenu(menu);
}
...
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Forest
Knows some wx things
Knows some wx things
Posts: 39
Joined: Fri Feb 06, 2009 3:58 pm

Post by Forest »

Thank you, tan!
Sorry for lame English... :)
Post Reply