void DoMoveToEndOfText();
void DoMoveToEndOfEntry();
+ // return true if currently text control has any selection
+ bool HasSelection() const
+ {
+ long from, to;
+ GetFocusedText()->GetSelection(&from, &to);
+ return from != to;
+ }
+
MyTextCtrl *m_text;
MyTextCtrl *m_password;
MyTextCtrl *m_enter;
#endif // wxUSE_LOG
private:
- // get the currently focused text control or return the default one is no
- // text ctrl has focus
- wxTextCtrl *GetFocusedText(wxTextCtrl *textDef);
+ // get the currently focused text control or return the default one
+ // (m_multitext) is no text ctrl has focus -- in any case, returns
+ // something non NULL
+ wxTextCtrl *GetFocusedText() const;
};
class MyFrame: public wxFrame
#if wxUSE_CLIPBOARD
void OnPasteFromClipboard( wxCommandEvent& WXUNUSED(event) )
- { m_panel->DoPasteFromClipboard(); }
+ {
+ wxLogMessage(_T("Pasting text from clipboard."));
+ m_panel->DoPasteFromClipboard();
+ }
void OnCopyToClipboard( wxCommandEvent& WXUNUSED(event) )
- { m_panel->DoCopyToClipboard(); }
+ {
+ wxLogMessage(_T("Copying text to clipboard."));
+ m_panel->DoCopyToClipboard();
+ }
+
+ void OnUpdatePasteFromClipboard(wxUpdateUIEvent& event)
+ {
+ wxClipboardLocker lockClip;
+
+ event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) );
+ }
+
+ void OnUpdateCopyToClipboard(wxUpdateUIEvent& event)
+ {
+ event.Enable( m_panel->HasSelection() );
+ }
#endif // wxUSE_CLIPBOARD
void OnAddTextFreeze( wxCommandEvent& WXUNUSED(event) )
#endif // wxUSE_TOOLTIPS
#if wxUSE_CLIPBOARD
+ // notice that we use non default accelerators on purpose here to compare
+ // their behaviour with the built in handling of standard Ctrl/Cmd-C/V
wxMenu *menuClipboard = new wxMenu;
- menuClipboard->Append(TEXT_CLIPBOARD_COPY, _T("&Copy\tCtrl-C"),
- _T("Copy the first line to the clipboard"));
- menuClipboard->Append(TEXT_CLIPBOARD_PASTE, _T("&Paste\tCtrl-V"),
+ menuClipboard->Append(TEXT_CLIPBOARD_COPY, _T("&Copy\tCtrl-Shift-C"),
+ _T("Copy the selection to the clipboard"));
+ menuClipboard->Append(TEXT_CLIPBOARD_PASTE, _T("&Paste\tCtrl-Shift-V"),
_T("Paste from clipboard to the text control"));
menu_bar->Append(menuClipboard, _T("&Clipboard"));
#endif // wxUSE_CLIPBOARD
SetSizer(topSizer);
}
-wxTextCtrl *MyPanel::GetFocusedText(wxTextCtrl *textDef)
+wxTextCtrl *MyPanel::GetFocusedText() const
{
wxWindow *win = FindFocus();
wxTextCtrl *text = win ? wxDynamicCast(win, wxTextCtrl) : NULL;
- return text ? text : textDef;
+ return text ? text : m_multitext;
}
#if wxUSE_CLIPBOARD
#if wxUSE_LOG
*m_log << _T("Successfully retrieved data from the clipboard.\n");
#endif // wxUSE_LOG
- *m_multitext << data.GetText() << _T("\n");
+ GetFocusedText()->AppendText(data.GetText());
}
else
{
// call has no effect under MSW.
wxTheClipboard->UsePrimarySelection();
- wxString text( m_multitext->GetLineText(0) );
+ wxString text( GetFocusedText()->GetStringSelection() );
if (text.IsEmpty())
{
void MyPanel::DoRemoveText()
{
- GetFocusedText(m_multitext)->Remove(0, 10);
+ GetFocusedText()->Remove(0, 10);
}
void MyPanel::DoReplaceText()
{
- GetFocusedText(m_multitext)->Replace(3, 8, _T("ABC"));
+ GetFocusedText()->Replace(3, 8, _T("ABC"));
}
void MyPanel::DoSelectText()
{
- GetFocusedText(m_multitext)->SetSelection(3, 8);
+ GetFocusedText()->SetSelection(3, 8);
}
//----------------------------------------------------------------------
#if wxUSE_CLIPBOARD
EVT_MENU(TEXT_CLIPBOARD_PASTE, MyFrame::OnPasteFromClipboard)
EVT_MENU(TEXT_CLIPBOARD_COPY, MyFrame::OnCopyToClipboard)
+
+ EVT_UPDATE_UI(TEXT_CLIPBOARD_PASTE, MyFrame::OnUpdatePasteFromClipboard)
+ EVT_UPDATE_UI(TEXT_CLIPBOARD_COPY, MyFrame::OnUpdateCopyToClipboard)
#endif // wxUSE_CLIPBOARD
EVT_MENU(TEXT_REMOVE, MyFrame::OnRemoveText)