Implement EmptyUndoBuffer() for wxTextCtrl in wxMSW too
The relevant code was already present in MSWCreateText(), so just extract it into its own function.
This commit is contained in:
@@ -64,6 +64,9 @@ public:
|
||||
|
||||
virtual void Redo() wxOVERRIDE;
|
||||
virtual bool CanRedo() const wxOVERRIDE;
|
||||
#if wxUSE_RICHEDIT
|
||||
virtual void EmptyUndoBuffer() wxOVERRIDE;
|
||||
#endif // wxUSE_RICHEDIT
|
||||
|
||||
virtual void SetInsertionPointEnd() wxOVERRIDE;
|
||||
virtual long GetInsertionPoint() const wxOVERRIDE;
|
||||
|
@@ -168,8 +168,9 @@ public:
|
||||
/**
|
||||
Delete the undo history.
|
||||
|
||||
Currently only implemented under macOS and only for multiline text
|
||||
controls, does nothing in the other ports.
|
||||
Currently only implemented in wxMSW (for controls using wxTE_RICH2
|
||||
style only) and wxOSX (for multiline text controls only), does nothing
|
||||
in the other ports or for the controls not using the appropriate styles.
|
||||
|
||||
@since 3.1.6
|
||||
*/
|
||||
|
@@ -690,33 +690,16 @@ bool wxTextCtrl::MSWCreateText(const wxString& value,
|
||||
::SendMessage(GetHwnd(), EM_SETMARGINS, wParam, lParam);
|
||||
}
|
||||
|
||||
#if wxUSE_RICHEDIT && wxUSE_OLE && defined(wxHAS_TOM_H)
|
||||
#if wxUSE_RICHEDIT
|
||||
// For RichEdit >= 4, SetFont(), called above from MSWCreateControl(), uses
|
||||
// EM_SETCHARFORMAT which affects the undo buffer, meaning that CanUndo()
|
||||
// for a newly created control returns true, which is unexpected. To avoid
|
||||
// this, we explicitly use Undo(tomFalse) here to clear the undo buffer.
|
||||
// And since Undo(tomFalse) also disables the undo buffer, we need to
|
||||
// enable it again immediately after clearing by calling Undo(tomTrue).
|
||||
// for a newly created control returns true, which is unexpected, so clear
|
||||
// the undo buffer.
|
||||
if ( GetRichVersion() >= 4 )
|
||||
{
|
||||
wxCOMPtr<IRichEditOle> pRichEditOle;
|
||||
if ( SendMessage(GetHwnd(), EM_GETOLEINTERFACE,
|
||||
0, (LPARAM)&pRichEditOle) && pRichEditOle )
|
||||
{
|
||||
wxCOMPtr<ITextDocument> pDoc;
|
||||
HRESULT hr = pRichEditOle->QueryInterface
|
||||
(
|
||||
wxIID_PPV_ARGS(ITextDocument, &pDoc)
|
||||
);
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
hr = pDoc->Undo(tomFalse, NULL);
|
||||
if ( SUCCEEDED(hr) )
|
||||
pDoc->Undo(tomTrue, NULL);
|
||||
EmptyUndoBuffer();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_RICHEDIT && wxHAS_TOM_H
|
||||
#endif // wxUSE_RICHEDIT
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2012,6 +1995,37 @@ bool wxTextCtrl::CanRedo() const
|
||||
return wxTextEntry::CanRedo();
|
||||
}
|
||||
|
||||
#if wxUSE_RICHEDIT
|
||||
|
||||
void wxTextCtrl::EmptyUndoBuffer()
|
||||
{
|
||||
#if wxUSE_OLE && defined(wxHAS_TOM_H)
|
||||
// We need to use Undo(tomFalse) to clear the undo buffer, but calling it
|
||||
// also disables the undo buffer, so we need to enable it again immediately
|
||||
// after clearing by calling Undo(tomTrue).
|
||||
if ( GetRichVersion() >= 4 )
|
||||
{
|
||||
wxCOMPtr<IRichEditOle> pRichEditOle;
|
||||
if ( SendMessage(GetHwnd(), EM_GETOLEINTERFACE,
|
||||
0, (LPARAM)&pRichEditOle) && pRichEditOle )
|
||||
{
|
||||
wxCOMPtr<ITextDocument> pDoc;
|
||||
HRESULT hr = pRichEditOle->QueryInterface
|
||||
(
|
||||
wxIID_PPV_ARGS(ITextDocument, &pDoc)
|
||||
);
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
hr = pDoc->Undo(tomFalse, NULL);
|
||||
if ( SUCCEEDED(hr) )
|
||||
pDoc->Undo(tomTrue, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_OLE && wxHAS_TOM_H
|
||||
}
|
||||
#endif // wxUSE_RICHEDIT
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// caret handling (Windows only)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user