1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UndoGuard.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "UndoGuard.hxx"
36 using namespace ::com::sun::star
;
38 using ::com::sun::star::uno::Reference
;
39 using ::com::sun::star::uno::Sequence
;
40 using ::rtl::OUString
;
45 UndoGuard_Base::UndoGuard_Base( const OUString
& rUndoString
46 , const uno::Reference
< chart2::XUndoManager
> & xUndoManager
47 , const uno::Reference
< frame::XModel
> & xModel
)
49 , m_xUndoManager( xUndoManager
)
50 , m_aUndoString( rUndoString
)
51 , m_bActionPosted( false )
55 UndoGuard_Base::~UndoGuard_Base()
59 void UndoGuard_Base::commitAction()
61 if( !m_bActionPosted
)
62 m_xUndoManager
->postAction( m_aUndoString
);
63 m_bActionPosted
= true;
66 //-----------------------------------------------------------------------------
68 UndoGuard::UndoGuard( const OUString
& rUndoString
69 , const uno::Reference
< chart2::XUndoManager
> & xUndoManager
70 , const uno::Reference
< frame::XModel
> & xModel
)
71 : UndoGuard_Base( rUndoString
, xUndoManager
, xModel
)
73 m_xUndoManager
->preAction( m_xModel
);
76 UndoGuard::~UndoGuard()
78 if( !m_bActionPosted
)
79 m_xUndoManager
->cancelAction();
82 //-----------------------------------------------------------------------------
84 UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString
& rUndoString
85 , const uno::Reference
< chart2::XUndoManager
> & xUndoManager
86 , const uno::Reference
< frame::XModel
> & xModel
)
87 : UndoGuard_Base( rUndoString
, xUndoManager
, xModel
)
89 m_xUndoManager
->preAction( m_xModel
);
92 UndoLiveUpdateGuard::~UndoLiveUpdateGuard()
94 if( !m_bActionPosted
)
95 m_xUndoManager
->cancelActionWithUndo( m_xModel
);
98 //-----------------------------------------------------------------------------
100 UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString
& rUndoString
101 , const uno::Reference
< chart2::XUndoManager
> & xUndoManager
102 , const uno::Reference
< frame::XModel
> & xModel
)
103 : UndoGuard_Base( rUndoString
, xUndoManager
, xModel
)
105 Sequence
< beans::PropertyValue
> aArgs(1);
106 aArgs
[0] = beans::PropertyValue(
107 OUString( RTL_CONSTASCII_USTRINGPARAM("WithData")), -1, uno::Any(),
108 beans::PropertyState_DIRECT_VALUE
);
109 m_xUndoManager
->preActionWithArguments( m_xModel
, aArgs
);
112 UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData()
114 if( !m_bActionPosted
)
115 m_xUndoManager
->cancelActionWithUndo( m_xModel
);
118 //-----------------------------------------------------------------------------
120 UndoGuardWithSelection::UndoGuardWithSelection( const rtl::OUString
& rUndoString
121 , const uno::Reference
< chart2::XUndoManager
> & xUndoManager
122 , const uno::Reference
< frame::XModel
> & xModel
)
123 : UndoGuard_Base( rUndoString
, xUndoManager
, xModel
)
125 Sequence
< beans::PropertyValue
> aArgs(1);
126 aArgs
[0] = beans::PropertyValue(
127 OUString( RTL_CONSTASCII_USTRINGPARAM("WithSelection")), -1, uno::Any(),
128 beans::PropertyState_DIRECT_VALUE
);
129 m_xUndoManager
->preActionWithArguments( m_xModel
, aArgs
);
132 UndoGuardWithSelection::~UndoGuardWithSelection()
134 if( !m_bActionPosted
)
135 m_xUndoManager
->cancelAction();