I create a series of custom wxBoxSizer objects, each with multiple controls, and set these into the scrolled window sizer. Each of these custom objects represents a data item, including its structure, rules and current value.
One of the controls on the custom sizers is MyTextCtrl, which handles such things as changing font color when the text value is changed by the user.
I added a context menu to MyTextCtrl so that I can, among other things, revert the modified value back to its original state. All this is working as I want it to.
However, when I invoke the context menu, after my menu runs it is followed by what I presume to be a default context menu for wxTextCtrl (it contains items Undo, Cut, Copy, Paste, etc.).
Here is my code for MyTextCtrl:
Code: Select all
// in the .h
class TXMLDataForm;
class TItemDef;
enum
{
POP_RESTORE = 3000,
POP_MOVE_TO_TOP,
POP_SHOW_DEF
};
class MyTextCtrl : public wxTextCtrl
{
private:
TXMLDataForm *FDataForm;
TItemDef *FItemDef;
public:
MyTextCtrl(wxWindow *parent, wxWindowID id, const wxString &value,
const wxPoint &pos, const wxSize &size, int style = 0)
: wxTextCtrl(parent, id, value, pos, size, style)
{
FDataForm = NULL;
FItemDef = NULL;
}
void SetDataForm(TXMLDataForm* data_form) { FDataForm = data_form; }
void SetItemDef(TItemDef* item_def) { FItemDef = item_def; }
void OnExitTextCtrl(wxFocusEvent& event); // for FValueText on DisplayDataSizer
void OnPopupMenu(wxContextMenuEvent& event);
void OnEvent(wxMouseEvent& event);
void OnRestoreOriginal(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
};
// in the .cpp
wxBEGIN_EVENT_TABLE(MyTextCtrl, wxTextCtrl)
EVT_CONTEXT_MENU(MyTextCtrl::OnPopupMenu)
EVT_MOUSE_EVENTS(MyTextCtrl::OnEvent)
EVT_MENU(POP_RESTORE, MyTextCtrl::OnRestoreOriginal) // handler for pop menu option 1
wxEND_EVENT_TABLE()
void MyTextCtrl::OnPopupMenu(wxContextMenuEvent& event)
{
wxMenu menu;
menu.Append(POP_RESTORE, "&Restore original value");
menu.Append(POP_MOVE_TO_TOP, "Move item to top of display");
menu.Append(POP_SHOW_DEF, "Show dictionary definition");
PopupMenu(&menu, ScreenToClient(event.GetPosition()));
event.Skip();
}
void MyTextCtrl::OnEvent(wxMouseEvent& event)
{
event.Skip();
}
void MyTextCtrl::OnRestoreOriginal(wxCommandEvent& event)
{
wxString t_value = this->GetValue();
if (FDataForm->RestoreOriginalValue(FItemDef, t_value))
{
this->ChangeValue(t_value);
this->SetForegroundColour(*wxBLACK);
}
event.Skip();
}
This is wxWidgets 3.1.1 on Win10-64, working in MS Visual Studio 2017 Community.
Thanks,
Kathleen