wxMSW: Added context menu for rich edit control, as per standard EDIT control

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17706 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2002-11-04 21:49:57 +00:00
parent d3f6d73cf8
commit f5acd489cb
3 changed files with 81 additions and 0 deletions

View File

@@ -188,6 +188,7 @@ Unix (Base/GUI):
wxMSW:
- fixed crashes in wxListCtrl under XP
- added context menu for rich edit wxTextCtrl
2.3.3
-----

View File

@@ -35,6 +35,7 @@ public:
Create(parent, id, value, pos, size, style, validator, name);
}
~wxTextCtrl();
bool Create(wxWindow *parent, wxWindowID id,
const wxString& value = wxEmptyString,
@@ -167,12 +168,20 @@ public:
void OnPaste(wxCommandEvent& event);
void OnUndo(wxCommandEvent& event);
void OnRedo(wxCommandEvent& event);
void OnDelete(wxCommandEvent& event);
void OnSelectAll(wxCommandEvent& event);
void OnUpdateCut(wxUpdateUIEvent& event);
void OnUpdateCopy(wxUpdateUIEvent& event);
void OnUpdatePaste(wxUpdateUIEvent& event);
void OnUpdateUndo(wxUpdateUIEvent& event);
void OnUpdateRedo(wxUpdateUIEvent& event);
void OnUpdateDelete(wxUpdateUIEvent& event);
void OnUpdateSelectAll(wxUpdateUIEvent& event);
// Show a context menu for Rich Edit controls (the standard
// EDIT control has one already)
void OnRightClick(wxMouseEvent& event);
protected:
// common part of all ctors
@@ -233,6 +242,8 @@ protected:
private:
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS(wxTextCtrl)
wxMenu* m_privateContextMenu;
};
#endif

View File

@@ -149,17 +149,25 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
EVT_CHAR(wxTextCtrl::OnChar)
EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
#if wxUSE_RICHEDIT
EVT_RIGHT_UP(wxTextCtrl::OnRightClick)
#endif
EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete)
EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll)
EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete)
EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll)
#ifdef __WIN16__
EVT_ERASE_BACKGROUND(wxTextCtrl::OnEraseBackground)
#endif
@@ -179,9 +187,19 @@ void wxTextCtrl::Init()
m_verRichEdit = 0;
#endif // wxUSE_RICHEDIT
m_privateContextMenu = NULL;
m_suppressNextUpdate = FALSE;
}
wxTextCtrl::~wxTextCtrl()
{
if (m_privateContextMenu)
{
delete m_privateContextMenu;
m_privateContextMenu = NULL;
}
}
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
@@ -1595,6 +1613,19 @@ void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
Redo();
}
void wxTextCtrl::OnDelete(wxCommandEvent& event)
{
long from, to;
GetSelection(& from, & to);
if (from != -1 && to != -1)
Remove(from, to);
}
void wxTextCtrl::OnSelectAll(wxCommandEvent& event)
{
SetSelection(-1, -1);
}
void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
{
event.Enable( CanCut() );
@@ -1620,6 +1651,44 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
event.Enable( CanRedo() );
}
void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event)
{
long from, to;
GetSelection(& from, & to);
event.Enable(from != -1 && to != -1 && from != to && IsEditable()) ;
}
void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event)
{
event.Enable(GetLastPosition() > 0);
}
void wxTextCtrl::OnRightClick(wxMouseEvent& event)
{
#if wxUSE_RICHEDIT
if (IsRich())
{
if (!m_privateContextMenu)
{
m_privateContextMenu = new wxMenu;
m_privateContextMenu->Append(wxID_UNDO, _("&Undo"));
m_privateContextMenu->Append(wxID_REDO, _("&Redo"));
m_privateContextMenu->AppendSeparator();
m_privateContextMenu->Append(wxID_CUT, _("Cu&t"));
m_privateContextMenu->Append(wxID_COPY, _("&Copy"));
m_privateContextMenu->Append(wxID_PASTE, _("&Paste"));
m_privateContextMenu->Append(wxID_CLEAR, _("&Delete"));
m_privateContextMenu->AppendSeparator();
m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All"));
}
PopupMenu(m_privateContextMenu, event.GetPosition());
return;
}
else
#endif
event.Skip();
}
// the rest of the file only deals with the rich edit controls
#if wxUSE_RICHEDIT