+bool wxTextCtrl::CanCopy() const
+{
+ // Can copy if there's a selection
+ long from, to;
+ GetSelection(& from, & to);
+ return (from != to) ;
+}
+
+bool wxTextCtrl::CanCut() const
+{
+ // Can cut if there's a selection
+ long from, to;
+ GetSelection(& from, & to);
+ return (from != to) ;
+}
+
+bool wxTextCtrl::CanPaste() const
+{
+#if wxUSE_RICHEDIT
+ if (m_isRich)
+ {
+ int dataFormat = 0; // 0 == any format
+ return (::SendMessage( GetHwnd(), EM_CANPASTE, (WPARAM) (UINT) dataFormat, 0) != 0);
+ }
+#endif
+ if (!IsEditable())
+ return FALSE;
+
+ // Standard edit control: check for straight text on clipboard
+ bool isTextAvailable = FALSE;
+ if (::OpenClipboard((HWND) wxTheApp->GetTopWindow()->GetHWND()))
+ {
+ isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
+ ::CloseClipboard();
+ }
+ return isTextAvailable;
+}
+
+// Undo/redo
+void wxTextCtrl::Undo()
+{
+ if (CanUndo())
+ {
+ ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+ }
+}
+
+void wxTextCtrl::Redo()
+{
+ if (CanRedo())
+ {
+ // Same as Undo, since Undo undoes the undo, i.e. a redo.
+ ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
+ }
+}
+
+bool wxTextCtrl::CanUndo() const
+{
+ return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
+}
+
+bool wxTextCtrl::CanRedo() const
+{
+ return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
+}
+
+// If the return values from and to are the same, there is no
+// selection.
+void wxTextCtrl::GetSelection(long* from, long* to) const
+{
+#if wxUSE_RICHEDIT
+ if (m_isRich)
+ {
+ CHARRANGE charRange;
+ ::SendMessage(GetHwnd(), EM_EXGETSEL, 0, (LPARAM) (CHARRANGE*) & charRange);
+
+ *from = charRange.cpMin;
+ *to = charRange.cpMax;
+
+ return;
+ }
+#endif
+ DWORD dwStart, dwEnd;
+ WPARAM wParam = (WPARAM) (DWORD*) & dwStart; // receives starting position
+ LPARAM lParam = (LPARAM) (DWORD*) & dwEnd; // receives ending position
+
+ ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
+
+ *from = dwStart;
+ *to = dwEnd;
+}
+
+bool wxTextCtrl::IsEditable() const
+{
+ long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
+
+ return ((style & ES_READONLY) == 0);
+}
+