diff options
author | Mathias Bauer <mba@openoffice.org> | 2011-02-03 15:53:56 +0100 |
---|---|---|
committer | Mathias Bauer <mba@openoffice.org> | 2011-02-03 15:53:56 +0100 |
commit | 76f355864a8c03b64ebfc71139f525a1fc25836a (patch) | |
tree | 189737059bcece8ceacb7abf0c1e3834caa123c5 /chart2/source/controller/main | |
parent | 894985ff00c217013cc360a77108fc68cd8647e7 (diff) | |
parent | 0ceb085ea2b49234664765161095f2e5911e2b3b (diff) |
CWS gnumake3: resync to m99
Diffstat (limited to 'chart2/source/controller/main')
24 files changed, 1193 insertions, 1502 deletions
diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx index 675bcf40e7a2..ac3ef57a1bd9 100644 --- a/chart2/source/controller/main/ChartController.cxx +++ b/chart2/source/controller/main/ChartController.cxx @@ -49,17 +49,15 @@ #include "macros.hxx" #include "dlg_CreationWizard.hxx" #include "dlg_ChartType.hxx" -//#include "svx/ActionDescriptionProvider.hxx" #include "AccessibleChartView.hxx" #include "DrawCommandDispatch.hxx" #include "ShapeController.hxx" -#include "UndoManager.hxx" +#include "UndoActions.hxx" #include <comphelper/InlineContainer.hxx> #include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> -#include <com/sun/star/chart2/XUndoSupplier.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> #include <com/sun/star/frame/XLoadable.hpp> #include <com/sun/star/util/XCloneable.hpp> @@ -67,6 +65,8 @@ #include <com/sun/star/util/XModeChangeBroadcaster.hpp> #include <com/sun/star/util/XModifyBroadcaster.hpp> #include <com/sun/star/frame/LayoutManagerEvents.hpp> +#include <com/sun/star/document/XUndoManagerSupplier.hpp> +#include <com/sun/star/document/XUndoAction.hpp> //------- // header for define RET_OK @@ -86,6 +86,7 @@ // object in the DTOR #include <svtools/acceleratorexecute.hxx> #include <svx/ActionDescriptionProvider.hxx> +#include <tools/diagnose_ex.h> // enable the following define to let the controller listen to model changes and // react on this by rebuilding the view @@ -133,7 +134,6 @@ ChartController::ChartController(uno::Reference<uno::XComponentContext> const & , m_eDrawMode( CHARTDRAW_SELECT ) { DBG_CTOR(ChartController,NULL); -// m_aDispatchContainer.setUndoManager( m_xUndoManager ); m_aDoubleClickTimer.SetTimeoutHdl( LINK( this, ChartController, DoubleClickWaitingHdl ) ); } @@ -622,9 +622,8 @@ void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent m_pChartWindow->Invalidate(); } - uno::Reference< chart2::XUndoSupplier > xUndoSupplier( getModel(), uno::UNO_QUERY ); - if( xUndoSupplier.is()) - m_xUndoManager.set( xUndoSupplier->getUndoManager()); + uno::Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW ); + m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW ); return sal_True; } @@ -1335,7 +1334,7 @@ void SAL_CALL ChartController::executeDispatch_ChartType() { // using assignment for broken gcc 3.3 UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_EDIT_CHARTTYPE ))), m_xUndoManager, getModel() ); + String( SchResId( STR_ACTION_EDIT_CHARTTYPE )), m_xUndoManager ); // /-- ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); @@ -1344,7 +1343,7 @@ void SAL_CALL ChartController::executeDispatch_ChartType() if( aDlg.Execute() == RET_OK ) { impl_adaptDataSeriesAutoResize(); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } // \-- } @@ -1360,7 +1359,7 @@ void SAL_CALL ChartController::executeDispatch_SourceData() // using assignment for broken gcc 3.3 UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_EDIT_DATA_RANGES ))), m_xUndoManager, getModel() ); + String( SchResId( STR_ACTION_EDIT_DATA_RANGES )), m_xUndoManager ); if( xChartDoc.is()) { // /-- @@ -1369,7 +1368,7 @@ void SAL_CALL ChartController::executeDispatch_SourceData() if( aDlg.Execute() == RET_OK ) { impl_adaptDataSeriesAutoResize(); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } // \-- } @@ -1387,14 +1386,14 @@ void SAL_CALL ChartController::executeDispatch_MoveSeries( sal_Bool bForward ) UndoGuardWithSelection aUndoGuard( ActionDescriptionProvider::createDescription( (bForward ? ActionDescriptionProvider::MOVE_TOTOP : ActionDescriptionProvider::MOVE_TOBOTTOM), - ::rtl::OUString( String( SchResId( STR_OBJECT_DATASERIES )))), - m_xUndoManager, getModel()); + String( SchResId( STR_OBJECT_DATASERIES ))), + m_xUndoManager ); bool bChanged = DiagramHelper::moveSeries( ChartModelHelper::findDiagram( getModel() ), xGivenDataSeries, bForward ); if( bChanged ) { m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( aObjectCID, bForward ) ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -1454,13 +1453,21 @@ void SAL_CALL ChartController::modified( const lang::EventObject& /* aEvent */ ) IMPL_LINK( ChartController, NotifyUndoActionHdl, SdrUndoAction*, pUndoAction ) { + ENSURE_OR_RETURN( pUndoAction, "invalid Undo action", 1L ); + ::rtl::OUString aObjectCID = m_aSelection.getSelectedCID(); if ( aObjectCID.getLength() == 0 ) { - UndoManager* pUndoManager = UndoManager::getImplementation( m_xUndoManager ); - if ( pUndoManager ) + try + { + const Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW ); + const Reference< document::XUndoManager > xUndoManager( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW ); + const Reference< document::XUndoAction > xAction( new impl::ShapeUndoElement( *pUndoAction ) ); + xUndoManager->addUndoAction( xAction ); + } + catch( const uno::Exception& ) { - pUndoManager->addShapeUndoAction( pUndoAction ); + DBG_UNHANDLED_EXCEPTION(); } } return 0L; diff --git a/chart2/source/controller/main/ChartController.hxx b/chart2/source/controller/main/ChartController.hxx index f2b64eb7a9c5..7c06a4ad4ca2 100644 --- a/chart2/source/controller/main/ChartController.hxx +++ b/chart2/source/controller/main/ChartController.hxx @@ -42,7 +42,7 @@ #include <cppuhelper/implbase12.hxx> #include <com/sun/star/accessibility/XAccessible.hpp> -#include <com/sun/star/chart2/XUndoManager.hpp> +#include <com/sun/star/document/XUndoManager.hpp> #include <com/sun/star/frame/XController.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> #include <com/sun/star/frame/XDispatch.hpp> @@ -89,6 +89,8 @@ namespace chart { //............................................................................. +class UndoGuard; + enum ChartDrawMode { CHARTDRAW_INSERT, CHARTDRAW_SELECT }; class WindowController @@ -578,7 +580,8 @@ private: bool volatile m_bConnectingToView; - ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XUndoManager > m_xUndoManager; + ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > m_xUndoManager; + ::std::auto_ptr< UndoGuard > m_pTextActionUndoGuard; /// needed for dispatching URLs in FeatureStateEvents mutable ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer; diff --git a/chart2/source/controller/main/ChartController_EditData.cxx b/chart2/source/controller/main/ChartController_EditData.cxx index 0248732a63a7..7c9bfe0c3986 100644 --- a/chart2/source/controller/main/ChartController_EditData.cxx +++ b/chart2/source/controller/main/ChartController_EditData.cxx @@ -66,12 +66,12 @@ void ChartController::executeDispatch_EditData() ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); // using assignment for broken gcc 3.3 UndoLiveUpdateGuardWithData aUndoGuard = UndoLiveUpdateGuardWithData( - ::rtl::OUString( String( SchResId( STR_ACTION_EDIT_CHART_DATA ))), - m_xUndoManager, getModel() ); + String( SchResId( STR_ACTION_EDIT_CHART_DATA )), + m_xUndoManager ); DataEditor aDataEditorDialog( pParent, xChartDoc, m_xCC ); // the dialog has no OK/Cancel aDataEditorDialog.Execute(); - aUndoGuard.commitAction(); + aUndoGuard.commit(); // \-- } } diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx index 0a7a4057ef9a..b6928ac99284 100644 --- a/chart2/source/controller/main/ChartController_Insert.cxx +++ b/chart2/source/controller/main/ChartController_Insert.cxx @@ -44,7 +44,7 @@ #include "DiagramHelper.hxx" #include "macros.hxx" #include "chartview/DrawModelWrapper.hxx" -#include "chartview/NumberFormatterWrapper.hxx" +#include "NumberFormatterWrapper.hxx" #include "ViewElementListProvider.hxx" #include "MultipleChartConverters.hxx" #include "ControllerLockGuard.hxx" @@ -121,8 +121,8 @@ void ChartController::executeDispatch_InsertAxes() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_AXES )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXES ))), + m_xUndoManager ); try { @@ -146,7 +146,7 @@ void ChartController::executeDispatch_InsertAxes() , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC , mpRefSizeProvider.get() ); if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -159,8 +159,8 @@ void ChartController::executeDispatch_InsertGrid() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_GRIDS )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRIDS ))), + m_xUndoManager ); try { @@ -180,7 +180,7 @@ void ChartController::executeDispatch_InsertGrid() bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC ); if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -196,8 +196,8 @@ void ChartController::executeDispatch_InsertTitles() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLES )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLES ))), + m_xUndoManager ); try { @@ -214,7 +214,7 @@ void ChartController::executeDispatch_InsertTitles() aDlg.getResult( aDialogOutput ); bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput ); if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -227,30 +227,30 @@ void ChartController::executeDispatch_DeleteLegend() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))), + m_xUndoManager ); LegendHelper::hideLegend( getModel() ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_InsertLegend() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))), + m_xUndoManager ); Reference< chart2::XLegend > xLegend = LegendHelper::showLegend( getModel(), m_xCC ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_OpenLegendDialog() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))), + m_xUndoManager ); try { @@ -264,7 +264,7 @@ void ChartController::executeDispatch_OpenLegendDialog() ControllerLockGuard aCLGuard( getModel() ); bool bChanged = aDlg.writeToModel( getModel() ); if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -280,8 +280,8 @@ void ChartController::executeDispatch_InsertMenu_DataLabels() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_DATALABELS )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_DATALABELS ))), + m_xUndoManager ); //if a series is selected insert labels for that series only: uno::Reference< chart2::XDataSeries > xSeries( @@ -298,7 +298,7 @@ void ChartController::executeDispatch_InsertMenu_DataLabels() bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true ); if( bSuccess ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); return; } @@ -330,7 +330,7 @@ void ChartController::executeDispatch_InsertMenu_DataLabels() ControllerLockGuard aCLGuard( getModel() ); bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -354,7 +354,7 @@ void ChartController::executeDispatch_InsertMenu_YErrorBars() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_ERRORS ) ), - m_xUndoManager, getModel() ); + m_xUndoManager ); try { @@ -380,7 +380,7 @@ void ChartController::executeDispatch_InsertMenu_YErrorBars() ControllerLockGuard aCLGuard( getModel() ); bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -393,19 +393,19 @@ void ChartController::executeDispatch_InsertMeanValue() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))), + m_xUndoManager ); lcl_InsertMeanValueLine( m_xCC ).operator()( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() )); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_InsertMenu_MeanValues() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))), + m_xUndoManager ); uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); @@ -420,7 +420,7 @@ void ChartController::executeDispatch_InsertMenu_MeanValues() DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() ))); ::std::for_each( aSeries.begin(), aSeries.end(), lcl_InsertMeanValueLine( m_xCC )); } - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_InsertMenu_Trendlines() @@ -437,7 +437,7 @@ void ChartController::executeDispatch_InsertMenu_Trendlines() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_CURVE ) ), - m_xUndoManager, getModel() ); + m_xUndoManager ); try { @@ -460,7 +460,7 @@ void ChartController::executeDispatch_InsertMenu_Trendlines() ControllerLockGuard aCLGuard( getModel() ); bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -477,8 +477,8 @@ void ChartController::executeDispatch_InsertTrendline() { UndoLiveUpdateGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))), + m_xUndoManager ); // add a linear curve RegressionCurveHelper::addRegressionCurve( @@ -518,7 +518,7 @@ void ChartController::executeDispatch_InsertTrendline() ControllerLockGuard aCLGuard( getModel() ); aItemConverter.ApplyItemSet( *pOutItemSet ); } - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } } @@ -531,8 +531,8 @@ void ChartController::executeDispatch_InsertYErrorBars() { UndoLiveUpdateGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_ERROR_BARS )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_ERROR_BARS ))), + m_xUndoManager ); // add error bars with standard deviation uno::Reference< beans::XPropertySet > xErrorBarProp( @@ -568,7 +568,7 @@ void ChartController::executeDispatch_InsertYErrorBars() ControllerLockGuard aCLGuard( getModel() ); aItemConverter.ApplyItemSet( *pOutItemSet ); } - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } } @@ -591,11 +591,11 @@ void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 ) // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))), + m_xUndoManager ); xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( true )); xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( bInsertR2 )); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } } @@ -608,10 +608,10 @@ void ChartController::executeDispatch_InsertR2Value() { UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))), + m_xUndoManager ); xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( true )); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -623,10 +623,10 @@ void ChartController::executeDispatch_DeleteR2Value() { UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))), + m_xUndoManager ); xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false )); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -638,10 +638,10 @@ void ChartController::executeDispatch_DeleteMeanValue() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))), + m_xUndoManager ); RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -653,10 +653,10 @@ void ChartController::executeDispatch_DeleteTrendline() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))), + m_xUndoManager ); RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -668,10 +668,10 @@ void ChartController::executeDispatch_DeleteTrendlineEquation() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))), + m_xUndoManager ); RegressionCurveHelper::removeEquations( xRegCurveCnt ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -683,10 +683,10 @@ void ChartController::executeDispatch_DeleteYErrorBars() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))), + m_xUndoManager ); StatisticsHelper::removeErrorBars( xDataSeries ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -697,20 +697,20 @@ void ChartController::executeDispatch_InsertDataLabels() if( xSeries.is() ) { UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT, - ::rtl::OUString( String( SchResId( STR_OBJECT_DATALABELS )))), - m_xUndoManager, getModel() ); + String( SchResId( STR_OBJECT_DATALABELS ))), + m_xUndoManager ); DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } void ChartController::executeDispatch_InsertDataLabel() { UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT, - ::rtl::OUString( String( SchResId( STR_OBJECT_LABEL )))), - m_xUndoManager, getModel() ); + String( SchResId( STR_OBJECT_LABEL ))), + m_xUndoManager ); DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_DeleteDataLabels() @@ -720,44 +720,44 @@ void ChartController::executeDispatch_DeleteDataLabels() if( xSeries.is() ) { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE, - ::rtl::OUString( String( SchResId( STR_OBJECT_DATALABELS )))), - m_xUndoManager, getModel() ); + String( SchResId( STR_OBJECT_DATALABELS ))), + m_xUndoManager ); DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } void ChartController::executeDispatch_DeleteDataLabel() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE, - ::rtl::OUString( String( SchResId( STR_OBJECT_LABEL )))), - m_xUndoManager, getModel() ); + String( SchResId( STR_OBJECT_LABEL ))), + m_xUndoManager ); DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_ResetAllDataPoints() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT, - ::rtl::OUString( String( SchResId( STR_OBJECT_DATAPOINTS )))), - m_xUndoManager, getModel() ); + String( SchResId( STR_OBJECT_DATAPOINTS ))), + m_xUndoManager ); uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); if( xSeries.is() ) xSeries->resetAllDataPoints(); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_ResetDataPoint() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT, - ::rtl::OUString( String( SchResId( STR_OBJECT_DATAPOINT )))), - m_xUndoManager, getModel() ); + String( SchResId( STR_OBJECT_DATAPOINT ))), + m_xUndoManager ); uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY ); if( xSeries.is() ) { sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() ); xSeries->resetDataPoint( nPointIndex ); } - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_InsertAxisTitle() @@ -768,8 +768,8 @@ void ChartController::executeDispatch_InsertAxisTitle() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLE ))), + m_xUndoManager ); Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() ); sal_Int32 nDimensionIndex = -1; @@ -787,7 +787,7 @@ void ChartController::executeDispatch_InsertAxisTitle() ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider()); xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } /* @@ -809,8 +809,8 @@ void ChartController::executeDispatch_InsertAxis() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_AXIS )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXIS ))), + m_xUndoManager ); try { @@ -818,7 +818,7 @@ void ChartController::executeDispatch_InsertAxis() if( xAxis.is() ) { AxisHelper::makeAxisVisible( xAxis ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -831,8 +831,8 @@ void ChartController::executeDispatch_DeleteAxis() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_AXIS )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AXIS ))), + m_xUndoManager ); try { @@ -840,7 +840,7 @@ void ChartController::executeDispatch_DeleteAxis() if( xAxis.is() ) { AxisHelper::makeAxisInvisible( xAxis ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -853,8 +853,8 @@ void ChartController::executeDispatch_InsertMajorGrid() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))), + m_xUndoManager ); try { @@ -862,7 +862,7 @@ void ChartController::executeDispatch_InsertMajorGrid() if( xAxis.is() ) { AxisHelper::makeGridVisible( xAxis->getGridProperties() ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -875,8 +875,8 @@ void ChartController::executeDispatch_DeleteMajorGrid() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))), + m_xUndoManager ); try { @@ -884,7 +884,7 @@ void ChartController::executeDispatch_DeleteMajorGrid() if( xAxis.is() ) { AxisHelper::makeGridInvisible( xAxis->getGridProperties() ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -897,8 +897,8 @@ void ChartController::executeDispatch_InsertMinorGrid() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))), + m_xUndoManager ); try { @@ -908,7 +908,7 @@ void ChartController::executeDispatch_InsertMinorGrid() Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++) AxisHelper::makeGridVisible( aSubGrids[nN] ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) @@ -921,8 +921,8 @@ void ChartController::executeDispatch_DeleteMinorGrid() { UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))), + m_xUndoManager ); try { @@ -932,7 +932,7 @@ void ChartController::executeDispatch_DeleteMinorGrid() Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() ); for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++) AxisHelper::makeGridInvisible( aSubGrids[nN] ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException& e) diff --git a/chart2/source/controller/main/ChartController_Position.cxx b/chart2/source/controller/main/ChartController_Position.cxx index 619d308ffad2..ceb6877e64e9 100644 --- a/chart2/source/controller/main/ChartController_Position.cxx +++ b/chart2/source/controller/main/ChartController_Position.cxx @@ -139,7 +139,7 @@ void SAL_CALL ChartController::executeDispatch_PositionAndSize() ActionDescriptionProvider::createDescription( ActionDescriptionProvider::POS_SIZE, ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aCID ))), - m_xUndoManager, getModel() ); + m_xUndoManager ); SfxAbstractTabDialog * pDlg = NULL; try @@ -174,7 +174,7 @@ void SAL_CALL ChartController::executeDispatch_PositionAndSize() , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight()) , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) ); if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } delete pDlg; diff --git a/chart2/source/controller/main/ChartController_Properties.cxx b/chart2/source/controller/main/ChartController_Properties.cxx index 649b9cb62f9d..29f1bfa9f389 100644 --- a/chart2/source/controller/main/ChartController_Properties.cxx +++ b/chart2/source/controller/main/ChartController_Properties.cxx @@ -720,11 +720,11 @@ void SAL_CALL ChartController::executeDlg_ObjectProperties( const ::rtl::OUStrin UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT, ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))), - m_xUndoManager, getModel() ); + m_xUndoManager ); bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, false ); if( bSuccess ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } bool ChartController::executeDlg_ObjectProperties_withoutUndoGuard( const ::rtl::OUString& rObjectCID, bool bOkClickOnUnchangedDialogSouldBeRatedAsSuccessAlso ) @@ -838,15 +838,15 @@ void SAL_CALL ChartController::executeDispatch_View3D() { // using assignment for broken gcc 3.3 UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_EDIT_3D_VIEW ))), - m_xUndoManager, getModel()); + String( SchResId( STR_ACTION_EDIT_3D_VIEW )), + m_xUndoManager ); // /-- //open dialog ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); View3DDialog aDlg( m_pChartWindow, getModel(), m_pDrawModelWrapper->GetColorTable() ); if( aDlg.Execute() == RET_OK ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); // \-- } catch( uno::RuntimeException& e) diff --git a/chart2/source/controller/main/ChartController_TextEdit.cxx b/chart2/source/controller/main/ChartController_TextEdit.cxx index 6091fd8ef3f8..9354c911ad67 100644 --- a/chart2/source/controller/main/ChartController_TextEdit.cxx +++ b/chart2/source/controller/main/ChartController_TextEdit.cxx @@ -29,6 +29,8 @@ #include "precompiled_chart2.hxx" #include "ChartController.hxx" +#include "ResId.hxx" +#include "UndoGuard.hxx" #include "DrawViewWrapper.hxx" #include "ChartWindow.hxx" #include "TitleHelper.hxx" @@ -36,6 +38,7 @@ #include "macros.hxx" #include "ControllerLockGuard.hxx" #include "AccessibleTextHelper.hxx" +#include "Strings.hrc" #include "chartview/DrawModelWrapper.hxx" #include <svx/svdotext.hxx> @@ -81,7 +84,9 @@ void ChartController::StartTextEdit( const Point* pMousePixel ) if(!pTextObj) return; - m_xUndoManager->preAction( getModel()); + OSL_PRECOND( !m_pTextActionUndoGuard.get(), "ChartController::StartTextEdit: already have a TextUndoGuard!?" ); + m_pTextActionUndoGuard.reset( new UndoGuard( + String( SchResId( STR_ACTION_EDIT_TEXT ) ), m_xUndoManager ) ); SdrOutliner* pOutliner = m_pDrawViewWrapper->getOutliner(); //pOutliner->SetRefDevice(m_pChartWindow); //pOutliner->SetStyleSheetPool((SfxStyleSheetPool*)pStyleSheetPool); @@ -165,26 +170,11 @@ bool ChartController::EndTextEdit() TitleHelper::setCompleteString( aString, uno::Reference< ::com::sun::star::chart2::XTitle >::query( xPropSet ), m_xCC ); - try - { - m_xUndoManager->postAction( C2U("Edit Text") ); - } - catch( uno::RuntimeException& e) - { - ASSERT_EXCEPTION( e ); - } - } - else - { - try - { - m_xUndoManager->cancelAction(); - } - catch ( uno::RuntimeException& e ) - { - ASSERT_EXCEPTION( e ); - } + OSL_ENSURE( m_pTextActionUndoGuard.get(), "ChartController::EndTextEdit: no TextUndoGuard!" ); + if ( m_pTextActionUndoGuard.get() ) + m_pTextActionUndoGuard->commit(); } + m_pTextActionUndoGuard.reset(); } return true; } diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index 735cb9634671..945ccf4b4b34 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -102,7 +102,7 @@ namespace bool lcl_deleteDataSeries( const OUString & rCID, const Reference< frame::XModel > & xModel, - const Reference< chart2::XUndoManager > & xUndoManager ) + const Reference< document::XUndoManager > & xUndoManager ) { bool bResult = false; uno::Reference< chart2::XDataSeries > xSeries( ::chart::ObjectIdentifier::getDataSeriesForCID( rCID, xModel )); @@ -115,8 +115,8 @@ bool lcl_deleteDataSeries( { ::chart::UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( ::chart::SchResId( STR_OBJECT_DATASERIES )))), - xUndoManager, xModel ); + ActionDescriptionProvider::DELETE, String( ::chart::SchResId( STR_OBJECT_DATASERIES ))), + xUndoManager ); Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) ); uno::Reference< chart2::XAxis > xAxis( ::chart::DiagramHelper::getAttachedAxis( xSeries, xDiagram ) ); @@ -126,7 +126,7 @@ bool lcl_deleteDataSeries( ::chart::AxisHelper::hideAxisIfNoDataIsAttached( xAxis, xDiagram ); bResult = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } return bResult; @@ -135,7 +135,7 @@ bool lcl_deleteDataSeries( bool lcl_deleteDataCurve( const OUString & rCID, const Reference< frame::XModel > & xModel, - const Reference< chart2::XUndoManager > & xUndoManager ) + const Reference< document::XUndoManager > & xUndoManager ) { bool bResult = false; uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( @@ -145,11 +145,11 @@ bool lcl_deleteDataCurve( { ::chart::UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( ::chart::SchResId( STR_OBJECT_CURVE )))), - xUndoManager, xModel ); + ActionDescriptionProvider::DELETE, String( ::chart::SchResId( STR_OBJECT_CURVE ))), + xUndoManager ); ::chart::RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt ); bResult = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } return bResult; } @@ -235,8 +235,8 @@ void ChartController::executeDispatch_NewArrangement() { // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_REARRANGE_CHART ))), - m_xUndoManager, xModel ); + String( SchResId( STR_ACTION_REARRANGE_CHART )), + m_xUndoManager ); ControllerLockGuard aCtlLockGuard( xModel ); // diagram @@ -271,7 +271,7 @@ void ChartController::executeDispatch_NewArrangement() ::std::for_each( aRegressionCurves.begin(), aRegressionCurves.end(), RegressionCurveHelper::resetEquationPosition ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } catch( uno::RuntimeException & ex ) @@ -285,14 +285,14 @@ void ChartController::executeDispatch_ScaleText() ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_SCALE_TEXT ))), - m_xUndoManager, getModel() ); + String( SchResId( STR_ACTION_SCALE_TEXT )), + m_xUndoManager ); ControllerLockGuard aCtlLockGuard( getModel() ); ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProv( impl_createReferenceSizeProvider()); OSL_ASSERT( apRefSizeProv.get()); if( apRefSizeProv.get()) apRefSizeProv->toggleAutoResizeState(); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_Paste() @@ -655,12 +655,12 @@ bool ChartController::executeDispatch_Delete() // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLE )))), - m_xUndoManager, getModel()); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_TITLE ))), + m_xUndoManager ); TitleHelper::removeTitle( ObjectIdentifier::getTitleTypeForCID( aCID ), getModel() ); bReturn = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); break; } case OBJECTTYPE_LEGEND: @@ -674,11 +674,11 @@ bool ChartController::executeDispatch_Delete() // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))), + m_xUndoManager ); xLegendProp->setPropertyValue( C2U("Show"), uno::makeAny( false )); bReturn = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } break; @@ -709,11 +709,11 @@ bool ChartController::executeDispatch_Delete() // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE )))), - m_xUndoManager, getModel() ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))), + m_xUndoManager ); RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt ); bReturn = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } break; } @@ -732,15 +732,15 @@ bool ChartController::executeDispatch_Delete() // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION )))), - m_xUndoManager, xModel ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))), + m_xUndoManager ); { ControllerLockGuard aCtlLockGuard( xModel ); xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( false )); xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false )); } bReturn = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } break; } @@ -755,8 +755,8 @@ bool ChartController::executeDispatch_Delete() // using assignment for broken gcc 3.3 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( STR_OBJECT_ERROR_BARS )))), - m_xUndoManager, xModel ); + ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_ERROR_BARS ))), + m_xUndoManager ); { ControllerLockGuard aCtlLockGuard( xModel ); xErrorBarProp->setPropertyValue( @@ -764,7 +764,7 @@ bool ChartController::executeDispatch_Delete() uno::makeAny( ::com::sun::star::chart::ErrorBarStyle::NONE )); } bReturn = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } break; } @@ -780,7 +780,7 @@ bool ChartController::executeDispatch_Delete() ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE, ::rtl::OUString( String( SchResId( aObjectType == OBJECTTYPE_DATA_LABEL ? STR_OBJECT_LABEL : STR_OBJECT_DATALABELS )))), - m_xUndoManager, getModel() ); + m_xUndoManager ); chart2::DataPointLabel aLabel; xObjectProperties->getPropertyValue( C2U( "Label" ) ) >>= aLabel; aLabel.ShowNumber = false; @@ -795,7 +795,7 @@ bool ChartController::executeDispatch_Delete() else xObjectProperties->setPropertyValue( C2U( "Label" ), uno::makeAny(aLabel) ); bReturn = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } break; } @@ -844,7 +844,7 @@ void ChartController::executeDispatch_ToggleLegend() { Reference< frame::XModel > xModel( getModel() ); UndoGuard aUndoGuard = UndoGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_TOGGLE_LEGEND ))), m_xUndoManager, xModel ); + String( SchResId( STR_ACTION_TOGGLE_LEGEND )), m_xUndoManager ); Reference< beans::XPropertySet > xLegendProp( LegendHelper::getLegend( xModel ), uno::UNO_QUERY ); bool bChanged = false; if( xLegendProp.is()) @@ -871,14 +871,14 @@ void ChartController::executeDispatch_ToggleLegend() } if( bChanged ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } void ChartController::executeDispatch_ToggleGridHorizontal() { Reference< frame::XModel > xModel( getModel() ); UndoGuard aUndoGuard = UndoGuard( - ::rtl::OUString( String( SchResId( STR_ACTION_TOGGLE_GRID_HORZ ))), m_xUndoManager, xModel ); + String( SchResId( STR_ACTION_TOGGLE_GRID_HORZ )), m_xUndoManager ); Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( getModel() )); if( xDiagram.is()) { @@ -893,7 +893,7 @@ void ChartController::executeDispatch_ToggleGridHorizontal() else AxisHelper::showGrid( nDimensionIndex, nCooSysIndex, bIsMainGrid, xDiagram, m_xCC ); - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -911,9 +911,9 @@ void ChartController::impl_switchDiagramPositioningToExcludingPositioning() UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::POS_SIZE, ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)), - m_xUndoManager, m_aModel->getModel() ); + m_xUndoManager ); if( DiagramHelper::switchDiagramPositioningToExcludingPositioning( m_aModel->getModel(), true, true ) ) - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } // namespace chart diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx index 885e37126dc2..0a81048d771b 100644 --- a/chart2/source/controller/main/ChartController_Window.cxx +++ b/chart2/source/controller/main/ChartController_Window.cxx @@ -801,7 +801,11 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) if ( m_eDrawMode == CHARTDRAW_INSERT && pDrawViewWrapper->IsCreateObj() ) { pDrawViewWrapper->EndCreateObj( SDRCREATE_FORCEEND ); - impl_switchDiagramPositioningToExcludingPositioning(); + { + HiddenUndoContext aUndoContext( m_xUndoManager ); + // don't want the positioning Undo action to appear in the UI + impl_switchDiagramPositioningToExcludingPositioning(); + } if ( pDrawViewWrapper->AreObjectsMarked() ) { if ( pDrawViewWrapper->GetCurrentObjIdentifier() == OBJ_TEXT ) @@ -838,12 +842,12 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) if( pChartDragMethod ) { UndoGuard aUndoGuard( pChartDragMethod->getUndoDescription(), - m_xUndoManager, getModel() ); + m_xUndoManager ); if( pDrawViewWrapper->EndDragObj(false) ) { bDraggingDone = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } @@ -871,7 +875,7 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) ActionDescriptionProvider::createDescription( eActionType, ObjectNameProvider::getName( ObjectIdentifier::getObjectType( m_aSelection.getSelectedCID() ))), - m_xUndoManager, getModel() ); + m_xUndoManager ); bool bChanged = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() , getModel() , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight()) @@ -879,7 +883,7 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) if( bChanged ) { bDraggingDone = true; - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } } @@ -1832,7 +1836,7 @@ bool ChartController::impl_moveOrResizeObject( ObjectType eObjectType = ObjectIdentifier::getObjectType( rCID ); UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( - eActionType, ObjectNameProvider::getName( eObjectType )), m_xUndoManager, xChartModel ); + eActionType, ObjectNameProvider::getName( eObjectType )), m_xUndoManager ); { ControllerLockGuard aCLGuard( xChartModel ); if( bNeedShift ) @@ -1840,7 +1844,7 @@ bool ChartController::impl_moveOrResizeObject( if( bNeedResize || (eObjectType == OBJECTTYPE_DIAGRAM) )//Also set an explicat size at the diagram when an explicit position is set xObjProp->setPropertyValue( C2U("RelativeSize"), uno::makeAny( aRelSize )); } - aUndoGuard.commitAction(); + aUndoGuard.commit(); } } return bResult; diff --git a/chart2/source/controller/main/ChartDropTargetHelper.cxx b/chart2/source/controller/main/ChartDropTargetHelper.cxx index 8749ca1bc062..fd7dc3ad1744 100644 --- a/chart2/source/controller/main/ChartDropTargetHelper.cxx +++ b/chart2/source/controller/main/ChartDropTargetHelper.cxx @@ -137,58 +137,47 @@ sal_Int8 ChartDropTargetHelper::ExecuteDrop( const ExecuteDropEvent& rEvt ) // parent) if( bDataComesFromParent ) { + Reference< chart2::XDiagram > xDiagram( m_xChartDocument->getFirstDiagram() ); Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider()); - if( xDataProvider.is() && + if( xDataProvider.is() && xDiagram.is() && DataSourceHelper::allArgumentsForRectRangeDetected( m_xChartDocument )) { - DiagramHelper::tTemplateWithServiceName aTempWithServ( - DiagramHelper::getTemplateForDiagram( - m_xChartDocument->getFirstDiagram(), - Reference< lang::XMultiServiceFactory >( - m_xChartDocument->getChartTypeManager(), uno::UNO_QUERY ))); - if( aTempWithServ.first.is()) + Reference< chart2::data::XDataSource > xDataSource( + DataSourceHelper::pressUsedDataIntoRectangularFormat( m_xChartDocument )); + Sequence< beans::PropertyValue > aArguments( + xDataProvider->detectArguments( xDataSource )); + + OUString aOldRange; + beans::PropertyValue * pCellRange = 0; + for( sal_Int32 i=0; i<aArguments.getLength(); ++i ) { - Reference< chart2::data::XDataSource > xDataSource( - DataSourceHelper::pressUsedDataIntoRectangularFormat( m_xChartDocument )); - Sequence< beans::PropertyValue > aArguments( - xDataProvider->detectArguments( xDataSource )); - - OUString aOldRange; - beans::PropertyValue * pCellRange = 0; - for( sal_Int32 i=0; i<aArguments.getLength(); ++i ) + if( aArguments[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CellRangeRepresentation"))) { - if( aArguments[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CellRangeRepresentation"))) - { - pCellRange = (aArguments.getArray() + i); - aArguments[i].Value >>= aOldRange; - break; - } + pCellRange = (aArguments.getArray() + i); + aArguments[i].Value >>= aOldRange; + break; } - if( pCellRange ) + } + if( pCellRange ) + { + // copy means add ranges, move means replace + if( rEvt.mnAction == DND_ACTION_COPY ) + { + // @todo: using implcit knowledge that ranges can be + // merged with ";". This should be done more general + pCellRange->Value <<= (aOldRange + OUString( sal_Unicode(';')) + aRangeString ); + } + // move means replace range + else { - // copy means add ranges, move means replace - if( rEvt.mnAction == DND_ACTION_COPY ) - { - // @todo: using implcit knowledge that ranges can be - // merged with ";". This should be done more general - pCellRange->Value <<= (aOldRange + OUString( sal_Unicode(';')) + aRangeString ); - } - // move means replace range - else - { - pCellRange->Value <<= aRangeString; - } - - xDataSource.set( xDataProvider->createDataSource( aArguments )); - aTempWithServ.first->changeDiagramData( - m_xChartDocument->getFirstDiagram(), - xDataSource, - aArguments ); - - // always return copy state to avoid deletion of the - // dragged range - nResult = DND_ACTION_COPY; + pCellRange->Value <<= aRangeString; } + + xDataSource.set( xDataProvider->createDataSource( aArguments )); + xDiagram->setDiagramData( xDataSource, aArguments ); + + // always return copy state to avoid deletion of the dragged range + nResult = DND_ACTION_COPY; } } } diff --git a/chart2/source/controller/main/ChartModelClone.cxx b/chart2/source/controller/main/ChartModelClone.cxx new file mode 100755 index 000000000000..69991eb081df --- /dev/null +++ b/chart2/source/controller/main/ChartModelClone.cxx @@ -0,0 +1,280 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "precompiled_chart2.hxx" + +#include "ChartModelClone.hxx" +#include "ChartModelHelper.hxx" +#include "ControllerLockGuard.hxx" +#include "DataSourceHelper.hxx" + +/** === begin UNO includes === **/ +#include <com/sun/star/chart2/XAnyDescriptionAccess.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/chart2/XTitled.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/chart2/data/XDataSource.hpp> +#include <com/sun/star/chart2/data/XLabeledDataSequence.hpp> +/** === end UNO includes === **/ + +#include <comphelper/property.hxx> +#include <tools/diagnose_ex.h> + +//...................................................................................................................... +namespace chart +{ +//...................................................................................................................... + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::util::XCloneable; + using ::com::sun::star::chart2::XChartDocument; + using ::com::sun::star::chart2::XInternalDataProvider; + using ::com::sun::star::chart2::XAnyDescriptionAccess; + using ::com::sun::star::view::XSelectionSupplier; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::chart2::XTitled; + using ::com::sun::star::util::XModifiable; + using ::com::sun::star::chart2::data::XDataSource; + using ::com::sun::star::chart2::data::XLabeledDataSequence; + /** === end UNO using === **/ + + // ================================================================================================================= + // = helper + // ================================================================================================================= + namespace + { + Reference< XModel > lcl_cloneModel( const Reference< XModel > & xModel ) + { + Reference< XModel > xResult; + try + { + const Reference< XCloneable > xCloneable( xModel, UNO_QUERY_THROW ); + xResult.set( xCloneable->createClone(), UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return xResult; + } + + } + + // ================================================================================================================= + // = ChartModelClone + // ================================================================================================================= + // ----------------------------------------------------------------------------------------------------------------- + ChartModelClone::ChartModelClone( const Reference< XModel >& i_model, const ModelFacet i_facet ) + { + m_xModelClone.set( lcl_cloneModel( i_model ) ); + + try + { + if ( i_facet == E_MODEL_WITH_DATA ) + { + const Reference< XChartDocument > xChartDoc( m_xModelClone, UNO_QUERY_THROW ); + ENSURE_OR_THROW( xChartDoc->hasInternalDataProvider(), "invalid chart model" ); + + const Reference< XCloneable > xCloneable( xChartDoc->getDataProvider(), UNO_QUERY_THROW ); + m_xDataClone.set( xCloneable->createClone(), UNO_QUERY_THROW ); + } + + if ( i_facet == E_MODEL_WITH_SELECTION ) + { + const Reference< XSelectionSupplier > xSelSupp( m_xModelClone->getCurrentController(), UNO_QUERY_THROW ); + m_aSelection = xSelSupp->getSelection(); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + + // ----------------------------------------------------------------------------------------------------------------- + ChartModelClone::~ChartModelClone() + { + if ( !impl_isDisposed() ) + dispose(); + } + + // ----------------------------------------------------------------------------------------------------------------- + void ChartModelClone::dispose() + { + if ( impl_isDisposed() ) + return; + + try + { + Reference< XComponent > xComp( m_xModelClone, UNO_QUERY_THROW ); + xComp->dispose(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + m_xModelClone.clear(); + m_xDataClone.clear(); + m_aSelection.clear(); + } + + // ----------------------------------------------------------------------------------------------------------------- + ModelFacet ChartModelClone::getFacet() const + { + if ( m_aSelection.hasValue() ) + return E_MODEL_WITH_SELECTION; + if ( m_xDataClone.is() ) + return E_MODEL_WITH_DATA; + return E_MODEL; + } + + // ----------------------------------------------------------------------------------------------------------------- + void ChartModelClone::applyToModel( const Reference< XModel >& i_model ) const + { + applyModelContentToModel( i_model, m_xModelClone, m_xDataClone ); + + if ( m_aSelection.hasValue() ) + { + try + { + Reference< XSelectionSupplier > xCurrentSelectionSuppl( i_model->getCurrentController(), UNO_QUERY_THROW ); + xCurrentSelectionSuppl->select( m_aSelection ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } + + // ----------------------------------------------------------------------------------------------------------------- + namespace + { + void ImplApplyDataToModel( const Reference< XModel >& i_model, const Reference< XInternalDataProvider > & i_data ) + { + Reference< XChartDocument > xDoc( i_model, UNO_QUERY ); + OSL_ASSERT( xDoc.is() && xDoc->hasInternalDataProvider() ); + + // copy data from stored internal data provider + if( xDoc.is() && xDoc->hasInternalDataProvider()) + { + Reference< XAnyDescriptionAccess > xCurrentData( xDoc->getDataProvider(), UNO_QUERY ); + Reference< XAnyDescriptionAccess > xSavedData( i_data, UNO_QUERY ); + if ( xCurrentData.is() && xSavedData.is() ) + { + xCurrentData->setData( xSavedData->getData() ); + xCurrentData->setAnyRowDescriptions( xSavedData->getAnyRowDescriptions()); + xCurrentData->setAnyColumnDescriptions( xSavedData->getAnyColumnDescriptions()); + } + } + } + } + + // ----------------------------------------------------------------------------------------------------------------- + void ChartModelClone::applyModelContentToModel( const Reference< XModel >& i_model, + const Reference< XModel >& i_modelToCopyFrom, const Reference< XInternalDataProvider >& i_data ) + { + ENSURE_OR_RETURN_VOID( i_model.is(), "ChartModelElement::applyModelContentToModel: invalid source model!" ); + ENSURE_OR_RETURN_VOID( i_modelToCopyFrom.is(), "ChartModelElement::applyModelContentToModel: invalid source model!" ); + try + { + // /-- loccked controllers of destination + ControllerLockGuard aLockedControllers( i_model ); + Reference< XChartDocument > xSource( i_modelToCopyFrom, UNO_QUERY_THROW ); + Reference< XChartDocument > xDestination( i_model, UNO_QUERY_THROW ); + + // propagate the correct flag for plotting of hidden values to the data provider and all used sequences + ChartModelHelper::setIncludeHiddenCells( ChartModelHelper::isIncludeHiddenCells( i_modelToCopyFrom ) , i_model ); + + // diagram + xDestination->setFirstDiagram( xSource->getFirstDiagram() ); + + // main title + Reference< XTitled > xDestinationTitled( xDestination, UNO_QUERY_THROW ); + Reference< XTitled > xSourceTitled( xSource, UNO_QUERY_THROW ); + xDestinationTitled->setTitleObject( xSourceTitled->getTitleObject() ); + + // page background + ::comphelper::copyProperties( + xSource->getPageBackground(), + xDestination->getPageBackground() ); + + // apply data (not applied in standard Undo) + if ( i_data.is() ) + ImplApplyDataToModel( i_model, i_data ); + + // register all sequences at the internal data provider to get adapted + // indexes when columns are added/removed + if ( xDestination->hasInternalDataProvider() ) + { + Reference< XInternalDataProvider > xNewDataProvider( xDestination->getDataProvider(), UNO_QUERY ); + Reference< XDataSource > xUsedData( DataSourceHelper::getUsedData( i_model ) ); + if ( xUsedData.is() && xNewDataProvider.is() ) + { + Sequence< Reference< XLabeledDataSequence > > aData( xUsedData->getDataSequences() ); + for( sal_Int32 i=0; i<aData.getLength(); ++i ) + { + xNewDataProvider->registerDataSequenceForChanges( aData[i]->getValues() ); + xNewDataProvider->registerDataSequenceForChanges( aData[i]->getLabel() ); + } + } + } + + // restore modify status + Reference< XModifiable > xSourceMod( xSource, UNO_QUERY ); + Reference< XModifiable > xDestMod( xDestination, UNO_QUERY ); + if ( xSourceMod.is() && xDestMod.is() && !xSourceMod->isModified() ) + { + xDestMod->setModified( sal_False ); + } + // \-- loccked controllers of destination + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + +//...................................................................................................................... +} // namespace chart +//...................................................................................................................... diff --git a/chart2/source/controller/main/ChartModelClone.hxx b/chart2/source/controller/main/ChartModelClone.hxx new file mode 100755 index 000000000000..d5653b8e1ccc --- /dev/null +++ b/chart2/source/controller/main/ChartModelClone.hxx @@ -0,0 +1,89 @@ +/************************************************************************* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef CHART2_CHARTMODELCLONE_HXX +#define CHART2_CHARTMODELCLONE_HXX + +/** === begin UNO includes === **/ +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/chart2/XInternalDataProvider.hpp> +/** === end UNO includes === **/ + +#include <boost/noncopyable.hpp> + +//...................................................................................................................... +namespace chart +{ +//...................................................................................................................... + + //================================================================================================================== + //= ModelFacet + //================================================================================================================== + enum ModelFacet + { + E_MODEL, + E_MODEL_WITH_DATA, + E_MODEL_WITH_SELECTION + }; + + //================================================================================================================== + //= ChartModelClone + //================================================================================================================== + class ChartModelClone : public ::boost::noncopyable + { + public: + ChartModelClone( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& i_model, + const ModelFacet i_facet + ); + + ~ChartModelClone(); + + ModelFacet getFacet() const; + + void applyToModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& i_model ) const; + + static void applyModelContentToModel( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & i_model, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & i_modelToCopyFrom, + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XInternalDataProvider > & i_data ); + + void dispose(); + + private: + bool impl_isDisposed() const { return !m_xModelClone.is(); } + + private: + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModelClone; + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XInternalDataProvider > m_xDataClone; + ::com::sun::star::uno::Any m_aSelection; + }; + +//...................................................................................................................... +} // namespace chart +//...................................................................................................................... + +#endif // CHART2_CHARTMODELCLONE_HXX diff --git a/chart2/source/controller/main/CommandDispatchContainer.cxx b/chart2/source/controller/main/CommandDispatchContainer.cxx index e0d689340760..c0847a490ea1 100644 --- a/chart2/source/controller/main/CommandDispatchContainer.cxx +++ b/chart2/source/controller/main/CommandDispatchContainer.cxx @@ -75,12 +75,6 @@ void CommandDispatchContainer::setModel( m_xModel = xModel; } -// void CommandDispatchContainer::setUndoManager( -// const Reference< chart2::XUndoManager > & xUndoManager ) -// { -// m_xUndoManager = xUndoManager; -// } - void CommandDispatchContainer::setChartDispatch( const Reference< frame::XDispatch > xChartDispatch, const ::std::set< OUString > & rChartCommands ) diff --git a/chart2/source/controller/main/CommandDispatchContainer.hxx b/chart2/source/controller/main/CommandDispatchContainer.hxx index 1c8769e0a6d9..a5995253e059 100644 --- a/chart2/source/controller/main/CommandDispatchContainer.hxx +++ b/chart2/source/controller/main/CommandDispatchContainer.hxx @@ -28,7 +28,6 @@ #define CHART2_COMMANDDISPATCHCONTAINER_HXX #include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/chart2/XUndoManager.hpp> #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/frame/DispatchDescriptor.hpp> @@ -86,9 +85,6 @@ public: void setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel ); -// void setUndoManager( -// const ::com::sun::star::uno::Reference< -// ::com::sun::star::chart2::XUndoManager > & xUndoManager ); /** Set a chart dispatcher that is used for all commands contained in rChartCommands @@ -140,9 +136,8 @@ private: mutable tDispatchMap m_aCachedDispatches; mutable tDisposeVector m_aToBeDisposedDispatches; - ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; - ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > m_xModel; - ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XUndoManager > m_xUndoManager; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > m_xModel; ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > m_xChartDispatcher; ::std::set< ::rtl::OUString > m_aChartCommands; diff --git a/chart2/source/controller/main/ImplUndoManager.cxx b/chart2/source/controller/main/ImplUndoManager.cxx deleted file mode 100644 index 0976b7db286e..000000000000 --- a/chart2/source/controller/main/ImplUndoManager.cxx +++ /dev/null @@ -1,503 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_chart2.hxx" - -#include "ImplUndoManager.hxx" -#include "DisposeHelper.hxx" -#include "CommonFunctors.hxx" -#include "ControllerLockGuard.hxx" -#include "PropertyHelper.hxx" -#include "DataSourceHelper.hxx" -#include "ChartModelHelper.hxx" - -#include <com/sun/star/chart/XComplexDescriptionAccess.hpp> -#include <com/sun/star/chart2/XChartDocument.hpp> -#include <com/sun/star/chart2/XInternalDataProvider.hpp> -#include <com/sun/star/chart2/XTitled.hpp> -#include <com/sun/star/util/XCloneable.hpp> -#include <com/sun/star/util/XModifiable.hpp> -#include <com/sun/star/view/XSelectionSupplier.hpp> - -#include <boost/bind.hpp> -#include <algorithm> - -using namespace ::com::sun::star; - -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::rtl::OUString; -using ::com::sun::star::chart::XComplexDescriptionAccess; - -namespace chart -{ -namespace impl -{ - -void ImplApplyDataToModel( - Reference< frame::XModel > & xInOutModelToChange, - const Reference< chart2::XInternalDataProvider > & xData ) -{ - Reference< chart2::XChartDocument > xDoc( xInOutModelToChange, uno::UNO_QUERY ); - OSL_ASSERT( xDoc.is() && xDoc->hasInternalDataProvider()); - - // copy data from stored internal data provider - if( xDoc.is() && xDoc->hasInternalDataProvider()) - { - Reference< XComplexDescriptionAccess > xCurrentData( xDoc->getDataProvider(), uno::UNO_QUERY ); - Reference< XComplexDescriptionAccess > xSavedData( xData, uno::UNO_QUERY ); - if( xCurrentData.is() && xSavedData.is()) - { - xCurrentData->setData( xSavedData->getData()); - xCurrentData->setComplexRowDescriptions( xSavedData->getComplexRowDescriptions()); - xCurrentData->setComplexColumnDescriptions( xSavedData->getComplexColumnDescriptions()); - } - } -} - -// ---------------------------------------- - -UndoElement::UndoElement( - const OUString & rActionString, - const Reference< frame::XModel > & xModel ) : - m_aActionString( rActionString ) -{ - initialize( xModel ); -} - -UndoElement::UndoElement( - const Reference< frame::XModel > & xModel ) -{ - initialize( xModel ); -} - -UndoElement::UndoElement( const UndoElement & rOther ) : - m_aActionString( rOther.m_aActionString ) -{ - initialize( rOther.m_xModel ); -} - -UndoElement::~UndoElement() -{} - -void UndoElement::initialize( const Reference< frame::XModel > & xModel ) -{ - if ( xModel.is() ) - { - m_xModel.set( UndoElement::cloneModel( xModel ) ); - } -} - -void UndoElement::dispose() -{ - Reference< lang::XComponent > xComp( m_xModel, uno::UNO_QUERY ); - if( xComp.is()) - xComp->dispose(); - m_xModel.set( 0 ); -} - -void UndoElement::applyToModel( - Reference< frame::XModel > & xInOutModelToChange ) -{ - UndoElement::applyModelContentToModel( xInOutModelToChange, m_xModel ); -} - -UndoElement * UndoElement::createFromModel( - const Reference< frame::XModel > & xModel ) -{ - return new UndoElement( getActionString(), xModel ); -} - -void UndoElement::setActionString( const ::rtl::OUString & rActionString ) -{ - m_aActionString = rActionString; -} - -OUString UndoElement::getActionString() const -{ - return m_aActionString; -} - -Reference< frame::XModel > UndoElement::cloneModel( const Reference< frame::XModel > & xModel ) -{ - Reference< frame::XModel > xResult; - uno::Reference< util::XCloneable > xCloneable( xModel, uno::UNO_QUERY ); - OSL_ENSURE( xCloneable.is(), "Cannot clone model" ); - if( xCloneable.is()) - xResult.set( xCloneable->createClone(), uno::UNO_QUERY ); - - return xResult; -} - -void UndoElement::applyModelContentToModel( - Reference< frame::XModel > & xInOutModelToChange, - const Reference< frame::XModel > & xModelToCopyFrom, - const Reference< chart2::XInternalDataProvider > & xData /* = 0 */ ) -{ - - if( xModelToCopyFrom.is() && xInOutModelToChange.is()) - { - try - { - // /-- loccked controllers of destination - ControllerLockGuard aLockedControllers( xInOutModelToChange ); - Reference< chart2::XChartDocument > xSource( xModelToCopyFrom, uno::UNO_QUERY_THROW ); - Reference< chart2::XChartDocument > xDestination( xInOutModelToChange, uno::UNO_QUERY_THROW ); - - // propagate the correct flag for plotting of hidden values to the data provider and all used sequences - ChartModelHelper::setIncludeHiddenCells( ChartModelHelper::isIncludeHiddenCells( xModelToCopyFrom ) , xInOutModelToChange ); - - // diagram - xDestination->setFirstDiagram( xSource->getFirstDiagram()); - - // main title - Reference< chart2::XTitled > xDestinationTitled( xDestination, uno::UNO_QUERY_THROW ); - Reference< chart2::XTitled > xSourceTitled( xSource, uno::UNO_QUERY_THROW ); - xDestinationTitled->setTitleObject( xSourceTitled->getTitleObject()); - - // page background - comphelper::copyProperties( - xSource->getPageBackground(), - xDestination->getPageBackground() ); - - // apply data (not applied in standard Undo) - if( xData.is()) - ImplApplyDataToModel( xInOutModelToChange, xData ); - - // register all sequences at the internal data provider to get adapted - // indexes when columns are added/removed - if( xDestination->hasInternalDataProvider()) - { - Reference< chart2::XInternalDataProvider > xNewDataProvider( xDestination->getDataProvider(), uno::UNO_QUERY ); - Reference< chart2::data::XDataSource > xUsedData( DataSourceHelper::getUsedData( xInOutModelToChange )); - if( xUsedData.is() && xNewDataProvider.is()) - { - Sequence< Reference< chart2::data::XLabeledDataSequence > > aData( xUsedData->getDataSequences()); - for( sal_Int32 i=0; i<aData.getLength(); ++i ) - { - xNewDataProvider->registerDataSequenceForChanges( aData[i]->getValues()); - xNewDataProvider->registerDataSequenceForChanges( aData[i]->getLabel()); - } - } - } - - // restore modify status - Reference< util::XModifiable > xSourceMod( xSource, uno::UNO_QUERY ); - Reference< util::XModifiable > xDestMod( xDestination, uno::UNO_QUERY ); - if( xSourceMod.is() && xDestMod.is() && - ! xSourceMod->isModified() ) - { - xDestMod->setModified( sal_False ); - } - // \-- loccked controllers of destination - } - catch( uno::Exception & ) - { - } - } -} - -// ---------------------------------------- - -UndoElementWithData::UndoElementWithData( - const OUString & rActionString, - const Reference< frame::XModel > & xModel ) : - UndoElement( rActionString, xModel ) -{ - initializeData(); -} - -UndoElementWithData::UndoElementWithData( - const Reference< frame::XModel > & xModel ) : - UndoElement( xModel ) -{ - initializeData(); -} - - -UndoElementWithData::UndoElementWithData( - const UndoElementWithData & rOther ) : - UndoElement( rOther ) -{ - initializeData(); -} - -UndoElementWithData::~UndoElementWithData() -{} - -void UndoElementWithData::initializeData() -{ - try - { - Reference< chart2::XChartDocument > xChartDoc( m_xModel, uno::UNO_QUERY_THROW ); - OSL_ASSERT( xChartDoc->hasInternalDataProvider()); - if( xChartDoc->hasInternalDataProvider()) - { - Reference< util::XCloneable > xCloneable( xChartDoc->getDataProvider(), uno::UNO_QUERY ); - OSL_ENSURE( xCloneable.is(), "Cannot clone data" ); - if( xCloneable.is()) - m_xData.set( xCloneable->createClone(), uno::UNO_QUERY ); - } - } - catch( uno::Exception & ) - { - } -} - -void UndoElementWithData::dispose() -{ - UndoElement::dispose(); - m_xData.set( 0 ); -} - -void UndoElementWithData::applyToModel( - Reference< frame::XModel > & xInOutModelToChange ) -{ - UndoElement::applyModelContentToModel( xInOutModelToChange, m_xModel, m_xData ); -} - -UndoElement * UndoElementWithData::createFromModel( - const Reference< frame::XModel > & xModel ) -{ - return new UndoElementWithData( getActionString(), xModel ); -} - -// ======================================== - -// ---------------------------------------- - -UndoElementWithSelection::UndoElementWithSelection( - const OUString & rActionString, - const Reference< frame::XModel > & xModel ) : - UndoElement( rActionString, xModel ) -{ - initialize( xModel ); -} - -UndoElementWithSelection::UndoElementWithSelection( - const Reference< frame::XModel > & xModel ) : - UndoElement( xModel ) -{ - initialize( xModel ); -} - -UndoElementWithSelection::UndoElementWithSelection( - const UndoElementWithSelection & rOther ) : - UndoElement( rOther ) -{ - initialize( rOther.m_xModel ); -} - -UndoElementWithSelection::~UndoElementWithSelection() -{} - -void UndoElementWithSelection::initialize( const Reference< frame::XModel > & xModel ) -{ - try - { - uno::Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY ); - OSL_ASSERT( xSelSupp.is() ); - - if( xSelSupp.is() ) - m_aSelection = xSelSupp->getSelection(); - } - catch( const uno::Exception & ) - { - } -} - -void UndoElementWithSelection::dispose() -{ - UndoElement::dispose(); - m_aSelection.clear(); -} - -void UndoElementWithSelection::applyToModel( - Reference< frame::XModel > & xInOutModelToChange ) -{ - UndoElement::applyModelContentToModel( xInOutModelToChange, m_xModel ); - Reference< view::XSelectionSupplier > xCurrentSelectionSuppl( xInOutModelToChange->getCurrentController(), uno::UNO_QUERY ); - OSL_ASSERT( xCurrentSelectionSuppl.is() ); - - if( xCurrentSelectionSuppl.is()) - xCurrentSelectionSuppl->select( m_aSelection ); -} - -UndoElement * UndoElementWithSelection::createFromModel( - const Reference< frame::XModel > & xModel ) -{ - return new UndoElementWithSelection( getActionString(), xModel ); -} - -// ---------------------------------------- - -ShapeUndoElement::ShapeUndoElement( const OUString& rActionString, SdrUndoAction* pAction ) - :UndoElement( rActionString, Reference< frame::XModel >() ) - ,m_pAction( pAction ) -{ -} - -ShapeUndoElement::ShapeUndoElement( const ShapeUndoElement& rOther ) - :UndoElement( rOther ) - ,m_pAction( rOther.m_pAction ) -{ -} - -ShapeUndoElement::~ShapeUndoElement() -{ -} - -SdrUndoAction* ShapeUndoElement::getSdrUndoAction() -{ - return m_pAction; -} - -// ======================================== - -UndoStack::UndoStack() : - m_nSizeLimit( 1000 ) -{ -} - -UndoStack::~UndoStack() -{ - disposeAndClear(); -} - -void UndoStack::pop() -{ - if( ! empty()) - { - top()->dispose(); - delete top(); - m_aStack.pop_back(); - } -} - -void UndoStack::push( UndoElement * pElement ) -{ - m_aStack.push_back( pElement ); - applyLimitation(); -} - -UndoElement * UndoStack::top() const -{ - return m_aStack.back(); -} - -OUString UndoStack::topUndoString() const -{ - if( ! empty()) - return top()->getActionString(); - return OUString(); -} - -Sequence< OUString > UndoStack::getUndoStrings() const -{ - sal_Int32 nSize( static_cast< sal_Int32 >( m_aStack.size())); - Sequence< OUString > aResult( nSize ); - for( sal_Int32 i=0; i<nSize; ++i ) - aResult[i] = m_aStack[i]->getActionString(); - return aResult; -} - -bool UndoStack::empty() const -{ - return m_aStack.empty(); -} - -void UndoStack::disposeAndClear() -{ - ::std::for_each( m_aStack.begin(), m_aStack.end(), ::boost::mem_fn( & UndoElement::dispose )); - ::std::for_each( m_aStack.begin(), m_aStack.end(), CommonFunctors::DeletePtr< UndoElement >() ); - m_aStack.clear(); -} - -void UndoStack::limitSize( sal_Int32 nMaxSize ) -{ - m_nSizeLimit = nMaxSize; - applyLimitation(); -} - -void UndoStack::applyLimitation() -{ - if( m_aStack.size() > static_cast< sal_uInt32 >( m_nSizeLimit )) - { - tUndoStackType::iterator aBegin( m_aStack.begin()); - tUndoStackType::iterator aEnd( aBegin + (m_aStack.size() - m_nSizeLimit)); - // dispose and remove all undo elements that are over the limit - ::std::for_each( aBegin, aEnd, ::boost::mem_fn( & UndoElement::dispose )); - ::std::for_each( aBegin, aEnd, CommonFunctors::DeletePtr< UndoElement >() ); - m_aStack.erase( aBegin, aEnd ); - } -} - -// ================================================================================ - -namespace -{ -static const OUString aUndoStepsPropName( RTL_CONSTASCII_USTRINGPARAM("Steps")); -} // anonymous namespace - -UndoStepsConfigItem::UndoStepsConfigItem( ConfigItemListener & rListener ) : - ::utl::ConfigItem( OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Undo"))), - m_rListener( rListener ) -{ - EnableNotification( Sequence< OUString >( & aUndoStepsPropName, 1 )); -} - -UndoStepsConfigItem::~UndoStepsConfigItem() -{ -} - -void UndoStepsConfigItem::Notify( const Sequence< OUString > & aPropertyNames ) -{ - for( sal_Int32 nIdx=0; nIdx<aPropertyNames.getLength(); ++nIdx ) - { - if( aPropertyNames[nIdx].equals( aUndoStepsPropName )) - m_rListener.notify( aPropertyNames[nIdx] ); - } -} - -void UndoStepsConfigItem::Commit() -{ -} - -// mtehod is not const, because GetProperties is not const -sal_Int32 UndoStepsConfigItem::getUndoSteps() -{ - sal_Int32 nSteps = -1; - Sequence< uno::Any > aValues( - GetProperties( Sequence< OUString >( & aUndoStepsPropName, 1 ))); - if( aValues.getLength()) - aValues[0] >>= nSteps; - return nSteps; -} - -} // namespace impl -} // namespace chart diff --git a/chart2/source/controller/main/ImplUndoManager.hxx b/chart2/source/controller/main/ImplUndoManager.hxx deleted file mode 100644 index 4dde0bc65719..000000000000 --- a/chart2/source/controller/main/ImplUndoManager.hxx +++ /dev/null @@ -1,227 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -#ifndef CHART2_IMPLUNDOMANAGER_HXX -#define CHART2_IMPLUNDOMANAGER_HXX - -#include "ConfigItemListener.hxx" - -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/uno/Sequence.hxx> - -#include <rtl/ustring.hxx> -#include <unotools/configitem.hxx> - -#include <utility> -#include <deque> - - -class SdrUndoAction; - -namespace com { namespace sun { namespace star { -namespace chart2 { - class XInternalDataProvider; -} -}}} - - -namespace chart -{ -namespace impl -{ - -class UndoElement -{ -public: - UndoElement( const ::rtl::OUString & rActionString, - const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - UndoElement( const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - UndoElement( const UndoElement & rOther ); - virtual ~UndoElement(); - - virtual void dispose(); - virtual UndoElement * createFromModel( - const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - - virtual void applyToModel( - ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xInOutModelToChange ); - - void setActionString( const ::rtl::OUString & rActionString ); - ::rtl::OUString getActionString() const; - - static ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > cloneModel( - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModel ); - - static void applyModelContentToModel( - ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xInOutModelToChange, - const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > & xModelToCopyFrom, - const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XInternalDataProvider > & xData = 0 ); - -protected: - ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > m_xModel; - -private: - void initialize( const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - - ::rtl::OUString m_aActionString; -}; - -class UndoElementWithData : public UndoElement -{ -public: - UndoElementWithData( const ::rtl::OUString & rActionString, - const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - UndoElementWithData( const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - UndoElementWithData( const UndoElementWithData & rOther ); - virtual ~UndoElementWithData(); - - virtual void dispose(); - virtual UndoElement * createFromModel( - const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - - virtual void applyToModel( - ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xInOutModelToChange ); - -private: - void initializeData(); - - ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XInternalDataProvider > m_xData; -}; - -class UndoElementWithSelection : public UndoElement -{ -public: - UndoElementWithSelection( const ::rtl::OUString & rActionString, - const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - UndoElementWithSelection( const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - UndoElementWithSelection( const UndoElementWithSelection & rOther ); - virtual ~UndoElementWithSelection(); - - virtual void dispose(); - virtual UndoElement * createFromModel( - const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - - virtual void applyToModel( - ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xInOutModelToChange ); - -private: - void initialize( const ::com::sun::star::uno::Reference< - ::com::sun::star::frame::XModel > & xModel ); - - ::com::sun::star::uno::Any m_aSelection; -}; - -class ShapeUndoElement : public UndoElement -{ -public: - ShapeUndoElement( const ::rtl::OUString& rActionString, SdrUndoAction* pAction ); - ShapeUndoElement( const ShapeUndoElement& rOther ); - virtual ~ShapeUndoElement(); - - SdrUndoAction* getSdrUndoAction(); - -private: - SdrUndoAction* m_pAction; -}; - -/** Note that all models that are put into this container are at some point - disposed of inside this class. (At least in the destructor). That means - the models retrieved here should never be used, but instead their content - should be copied to a living model. - */ -class UndoStack -{ -public: - UndoStack(); - // disposes of all models left in the stack - ~UndoStack(); - - // removes he last undo action and disposes of the model - void pop(); - void push( UndoElement * rElement ); - - // precondition: !empty() - UndoElement * top() const; - ::rtl::OUString topUndoString() const; - - ::com::sun::star::uno::Sequence< ::rtl::OUString > getUndoStrings() const; - - bool empty() const; - void disposeAndClear(); - - // removes all actions that have been inserted more than nMaxSize steps ago. - // The models of those actions are disposed of - void limitSize( sal_Int32 nMaxSize ); - -private: - void applyLimitation(); - - typedef ::std::deque< UndoElement * > tUndoStackType; - - tUndoStackType m_aStack; - sal_Int32 m_nSizeLimit; -}; - -// ---------------------------------------- - -class UndoStepsConfigItem : public ::utl::ConfigItem -{ -public: - explicit UndoStepsConfigItem( ConfigItemListener & rListener ); - virtual ~UndoStepsConfigItem(); - - sal_Int32 getUndoSteps(); - -protected: - // ____ ::utl::ConfigItem ____ - virtual void Notify( const ::com::sun::star::uno::Sequence< ::rtl::OUString > & aPropertyNames ); - virtual void Commit(); - -private: - ConfigItemListener & m_rListener; -}; - - -} // namespace impl -} // namespace chart - -// CHART2_IMPLUNDOMANAGER_HXX -#endif diff --git a/chart2/source/controller/main/UndoActions.cxx b/chart2/source/controller/main/UndoActions.cxx new file mode 100644 index 000000000000..86c0e365f590 --- /dev/null +++ b/chart2/source/controller/main/UndoActions.cxx @@ -0,0 +1,178 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_chart2.hxx" + +#include "UndoActions.hxx" +#include "DisposeHelper.hxx" +#include "CommonFunctors.hxx" +#include "PropertyHelper.hxx" +#include "ChartModelClone.hxx" + +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/lang/DisposedException.hpp> + +#include <tools/diagnose_ex.h> +#include <svx/svdundo.hxx> + +#include <boost/bind.hpp> +#include <algorithm> + +using namespace ::com::sun::star; + +using ::rtl::OUString; + +namespace chart +{ +namespace impl +{ + + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::util::XCloneable; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::lang::DisposedException; + using ::com::sun::star::view::XSelectionSupplier; + using ::com::sun::star::chart2::XChartDocument; + using ::com::sun::star::document::UndoFailedException; + /** === end UNO using === **/ + +// --------------------------------------------------------------------------------------------------------------------- +UndoElement::UndoElement( const OUString& i_actionString, const Reference< XModel >& i_documentModel, const ::boost::shared_ptr< ChartModelClone >& i_modelClone ) + :UndoElement_MBase() + ,UndoElement_TBase( m_aMutex ) + ,m_sActionString( i_actionString ) + ,m_xDocumentModel( i_documentModel ) + ,m_pModelClone( i_modelClone ) +{ +} + +// --------------------------------------------------------------------------------------------------------------------- +UndoElement::~UndoElement() +{ +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UndoElement::disposing() +{ + if ( !!m_pModelClone ) + m_pModelClone->dispose(); + m_pModelClone.reset(); + m_xDocumentModel.clear(); +} + +// --------------------------------------------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL UndoElement::getTitle() throw (RuntimeException) +{ + return m_sActionString; +} + +// --------------------------------------------------------------------------------------------------------------------- +void UndoElement::impl_toggleModelState() +{ + // get a snapshot of the current state of our model + ::boost::shared_ptr< ChartModelClone > pNewClone( new ChartModelClone( m_xDocumentModel, m_pModelClone->getFacet() ) ); + // apply the previous snapshot to our model + m_pModelClone->applyToModel( m_xDocumentModel ); + // remember the new snapshot, for the next toggle + m_pModelClone = pNewClone; +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UndoElement::undo( ) throw (UndoFailedException, RuntimeException) +{ + impl_toggleModelState(); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL UndoElement::redo( ) throw (UndoFailedException, RuntimeException) +{ + impl_toggleModelState(); +} + +// ===================================================================================================================== +// = ShapeUndoElement +// ===================================================================================================================== + +// --------------------------------------------------------------------------------------------------------------------- +ShapeUndoElement::ShapeUndoElement( SdrUndoAction& i_sdrUndoAction ) + :ShapeUndoElement_MBase() + ,ShapeUndoElement_TBase( m_aMutex ) + ,m_pAction( &i_sdrUndoAction ) +{ +} + +// --------------------------------------------------------------------------------------------------------------------- +ShapeUndoElement::~ShapeUndoElement() +{ +} + +// --------------------------------------------------------------------------------------------------------------------- +::rtl::OUString SAL_CALL ShapeUndoElement::getTitle() throw (RuntimeException) +{ + if ( !m_pAction ) + throw DisposedException( ::rtl::OUString(), *this ); + return m_pAction->GetComment(); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL ShapeUndoElement::undo( ) throw (UndoFailedException, RuntimeException) +{ + if ( !m_pAction ) + throw DisposedException( ::rtl::OUString(), *this ); + m_pAction->Undo(); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL ShapeUndoElement::redo( ) throw (UndoFailedException, RuntimeException) +{ + if ( !m_pAction ) + throw DisposedException( ::rtl::OUString(), *this ); + m_pAction->Redo(); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SAL_CALL ShapeUndoElement::disposing() +{ +} + +} // namespace impl +} // namespace chart diff --git a/chart2/source/controller/main/UndoActions.hxx b/chart2/source/controller/main/UndoActions.hxx new file mode 100644 index 000000000000..2c98d6af1d54 --- /dev/null +++ b/chart2/source/controller/main/UndoActions.hxx @@ -0,0 +1,134 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef CHART2_IMPLUNDOMANAGER_HXX +#define CHART2_IMPLUNDOMANAGER_HXX + +#include "ConfigItemListener.hxx" + +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/document/XUndoAction.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <rtl/ustring.hxx> +#include <unotools/configitem.hxx> +#include <cppuhelper/compbase1.hxx> +#include <cppuhelper/basemutex.hxx> + +#include <utility> +#include <deque> + +#include <boost/noncopyable.hpp> +#include <boost/shared_ptr.hpp> + +class SdrUndoAction; + +namespace com { namespace sun { namespace star { +namespace chart2 { + class XInternalDataProvider; +} +}}} + + +namespace chart +{ +class ChartModelClone; + +namespace impl +{ + +typedef ::cppu::BaseMutex UndoElement_MBase; +typedef ::cppu::WeakComponentImplHelper1< ::com::sun::star::document::XUndoAction > UndoElement_TBase; + +class UndoElement :public UndoElement_MBase + ,public UndoElement_TBase + ,public ::boost::noncopyable +{ +public: + /** creates a new undo action + + @param i_actionString + is the title of the Undo action + @param i_documentModel + is the actual document model which the undo actions operates on + @param i_modelClone + is the cloned model from before the changes, which the Undo action represents, have been applied. + Upon <member>invoking</member>, the clone model is applied to the document model. + */ + UndoElement( const ::rtl::OUString & i_actionString, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& i_documentModel, + const ::boost::shared_ptr< ChartModelClone >& i_modelClone + ); + + // XUndoAction + virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL undo( ) throw (::com::sun::star::document::UndoFailedException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL redo( ) throw (::com::sun::star::document::UndoFailedException, ::com::sun::star::uno::RuntimeException); + + // OComponentHelper + virtual void SAL_CALL disposing(); + +protected: + virtual ~UndoElement(); + +private: + void impl_toggleModelState(); + +private: + ::rtl::OUString m_sActionString; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xDocumentModel; + ::boost::shared_ptr< ChartModelClone > m_pModelClone; +}; + + +typedef ::cppu::BaseMutex ShapeUndoElement_MBase; +typedef ::cppu::WeakComponentImplHelper1< ::com::sun::star::document::XUndoAction > ShapeUndoElement_TBase; +class ShapeUndoElement :public ShapeUndoElement_MBase + ,public ShapeUndoElement_TBase +{ +public: + ShapeUndoElement( SdrUndoAction& i_sdrUndoAction ); + + // XUndoAction + virtual ::rtl::OUString SAL_CALL getTitle() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL undo( ) throw (::com::sun::star::document::UndoFailedException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL redo( ) throw (::com::sun::star::document::UndoFailedException, ::com::sun::star::uno::RuntimeException); + + // OComponentHelper + virtual void SAL_CALL disposing(); + +protected: + virtual ~ShapeUndoElement(); + +private: + SdrUndoAction* m_pAction; +}; + +} // namespace impl +} // namespace chart + +// CHART2_IMPLUNDOMANAGER_HXX +#endif diff --git a/chart2/source/controller/main/UndoCommandDispatch.cxx b/chart2/source/controller/main/UndoCommandDispatch.cxx index 128a4b4091d0..487def377d5c 100644 --- a/chart2/source/controller/main/UndoCommandDispatch.cxx +++ b/chart2/source/controller/main/UndoCommandDispatch.cxx @@ -29,13 +29,15 @@ #include "precompiled_chart2.hxx" #include "UndoCommandDispatch.hxx" +#include "ResId.hxx" #include "macros.hxx" -#include <com/sun/star/chart2/XUndoSupplier.hpp> #include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/document/XUndoManagerSupplier.hpp> #include <vos/mutex.hxx> #include <vcl/svapp.hxx> +#include <tools/diagnose_ex.h> // for ressource strings STR_UNDO and STR_REDO #include <svtools/svtools.hrc> @@ -56,10 +58,8 @@ UndoCommandDispatch::UndoCommandDispatch( CommandDispatch( xContext ), m_xModel( xModel ) { - Reference< chart2::XUndoSupplier > xUndoSupplier( xModel, uno::UNO_QUERY ); - OSL_ASSERT( xUndoSupplier.is()); - if( xUndoSupplier.is()) - m_xUndoManager.set( xUndoSupplier->getUndoManager()); + uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW ); + m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW ); } UndoCommandDispatch::~UndoCommandDispatch() @@ -68,10 +68,8 @@ UndoCommandDispatch::~UndoCommandDispatch() void UndoCommandDispatch::initialize() { Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY ); - if( xBroadcaster.is() ) - { - xBroadcaster->addModifyListener( this ); - } + ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" ); + xBroadcaster->addModifyListener( this ); } void UndoCommandDispatch::fireStatusEvent( @@ -82,23 +80,23 @@ void UndoCommandDispatch::fireStatusEvent( { bool bFireAll = (rURL.getLength() == 0); uno::Any aUndoState, aRedoState; - if( m_xUndoManager->undoPossible()) + if( m_xUndoManager->isUndoPossible()) { // using assignment for broken gcc 3.3 OUString aUndo = OUString( String( SvtResId( STR_UNDO ))); - aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoString()); + aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle()); } - if( m_xUndoManager->redoPossible()) + if( m_xUndoManager->isRedoPossible()) { // using assignment for broken gcc 3.3 OUString aRedo = OUString( String( SvtResId( STR_REDO ))); - aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoString()); + aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle()); } if( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Undo"))) - fireStatusEventForURL( C2U(".uno:Undo"), aUndoState, m_xUndoManager->undoPossible(), xSingleListener ); + fireStatusEventForURL( C2U(".uno:Undo"), aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener ); if( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Redo"))) - fireStatusEventForURL( C2U(".uno:Redo"), aRedoState, m_xUndoManager->redoPossible(), xSingleListener ); + fireStatusEventForURL( C2U(".uno:Redo"), aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener ); } } @@ -113,10 +111,21 @@ void SAL_CALL UndoCommandDispatch::dispatch( // why is it necessary to lock the solar mutex here? // /-- ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); - if( URL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Undo" ))) - m_xUndoManager->undo( m_xModel ); - else - m_xUndoManager->redo( m_xModel ); + try + { + if( URL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Undo" ))) + m_xUndoManager->undo(); + else + m_xUndoManager->redo(); + } + catch( const document::UndoFailedException& ) + { + // silently ignore + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } // \-- } } @@ -126,6 +135,7 @@ void SAL_CALL UndoCommandDispatch::dispatch( void SAL_CALL UndoCommandDispatch::disposing() { Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY ); + OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" ); if( xBroadcaster.is() ) { xBroadcaster->removeModifyListener( this ); diff --git a/chart2/source/controller/main/UndoCommandDispatch.hxx b/chart2/source/controller/main/UndoCommandDispatch.hxx index 28fb813f63de..891ab8b019e5 100644 --- a/chart2/source/controller/main/UndoCommandDispatch.hxx +++ b/chart2/source/controller/main/UndoCommandDispatch.hxx @@ -30,15 +30,12 @@ #include "CommandDispatch.hxx" #include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/chart2/XUndoManager.hpp> +#include <com/sun/star/document/XUndoManager.hpp> namespace chart { /** This is a CommandDispatch implementation for Undo and Redo. - - You need to pass an UndoManager to this class that is then used for Undo and - Redo. The changes are applied to the given XModel. */ class UndoCommandDispatch : public CommandDispatch { @@ -77,7 +74,7 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xModel; ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XUndoManager > m_xUndoManager; + ::com::sun::star::document::XUndoManager > m_xUndoManager; }; } // namespace chart diff --git a/chart2/source/controller/main/UndoGuard.cxx b/chart2/source/controller/main/UndoGuard.cxx index 8513b6ba9093..52ea27aa8d49 100644 --- a/chart2/source/controller/main/UndoGuard.cxx +++ b/chart2/source/controller/main/UndoGuard.cxx @@ -29,6 +29,12 @@ #include "precompiled_chart2.hxx" #include "UndoGuard.hxx" +#include "ChartModelClone.hxx" +#include "UndoActions.hxx" + +#include <com/sun/star/container/XChild.hpp> + +#include <tools/diagnose_ex.h> using namespace ::com::sun::star; @@ -39,105 +45,154 @@ using ::rtl::OUString; namespace chart { -UndoGuard_Base::UndoGuard_Base( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : m_xModel( xModel ) - , m_xUndoManager( xUndoManager ) - , m_aUndoString( rUndoString ) - , m_bActionPosted( false ) +//----------------------------------------------------------------------------- + +UndoGuard::UndoGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager > & i_undoManager, + const ModelFacet i_facet ) + :m_xChartModel( i_undoManager->getParent(), uno::UNO_QUERY_THROW ) + ,m_xUndoManager( i_undoManager ) + ,m_pDocumentSnapshot() + ,m_aUndoString( i_undoString ) + ,m_bActionPosted( false ) { + m_pDocumentSnapshot.reset( new ChartModelClone( m_xChartModel, i_facet ) ); } -UndoGuard_Base::~UndoGuard_Base() +//----------------------------------------------------------------------------- + +UndoGuard::~UndoGuard() { + if ( !!m_pDocumentSnapshot ) + discardSnapshot(); } -void UndoGuard_Base::commitAction() +//----------------------------------------------------------------------------- + +void UndoGuard::commit() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->postAction( m_aUndoString ); + if ( !m_bActionPosted && !!m_pDocumentSnapshot ) + { + try + { + const Reference< document::XUndoAction > xAction( new impl::UndoElement( m_aUndoString, m_xChartModel, m_pDocumentSnapshot ) ); + m_pDocumentSnapshot.reset(); // don't dispose, it's data went over to the UndoElement + m_xUndoManager->addUndoAction( xAction ); + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } m_bActionPosted = true; } //----------------------------------------------------------------------------- -UndoGuard::UndoGuard( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) +void UndoGuard::rollback() { - if( m_xUndoManager.is() ) - m_xUndoManager->preAction( m_xModel ); + ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" ); + m_pDocumentSnapshot->applyToModel( m_xChartModel ); + discardSnapshot(); } -UndoGuard::~UndoGuard() +//----------------------------------------------------------------------------- +void UndoGuard::discardSnapshot() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelAction(); + ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" ); + m_pDocumentSnapshot->dispose(); + m_pDocumentSnapshot.reset(); } //----------------------------------------------------------------------------- -UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) +UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard( i_undoString, i_undoManager, E_MODEL ) { - if( m_xUndoManager.is() ) - m_xUndoManager->preAction( m_xModel ); } UndoLiveUpdateGuard::~UndoLiveUpdateGuard() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelActionWithUndo( m_xModel ); + if ( !isActionPosted() ) + rollback(); } //----------------------------------------------------------------------------- -UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( const OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) +UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData( + const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard( i_undoString, i_undoManager, E_MODEL_WITH_DATA ) { - if( m_xUndoManager.is() ) - { - Sequence< beans::PropertyValue > aArgs(1); - aArgs[0] = beans::PropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM("WithData")), -1, uno::Any(), - beans::PropertyState_DIRECT_VALUE ); - m_xUndoManager->preActionWithArguments( m_xModel, aArgs ); - } } UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelActionWithUndo( m_xModel ); + if ( !isActionPosted() ) + rollback(); } //----------------------------------------------------------------------------- -UndoGuardWithSelection::UndoGuardWithSelection( const rtl::OUString& rUndoString - , const uno::Reference< chart2::XUndoManager > & xUndoManager - , const uno::Reference< frame::XModel > & xModel ) - : UndoGuard_Base( rUndoString, xUndoManager, xModel ) +UndoGuardWithSelection::UndoGuardWithSelection( + const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager ) + :UndoGuard( i_undoString, i_undoManager, E_MODEL_WITH_SELECTION ) { - if( m_xUndoManager.is() ) +} + +//----------------------------------------------------------------------------- + +UndoGuardWithSelection::~UndoGuardWithSelection() +{ + if ( !isActionPosted() ) + rollback(); +} + +//----------------------------------------------------------------------------- + +UndoContext::UndoContext( const Reference< document::XUndoManager > & i_undoManager, const ::rtl::OUString& i_undoTitle ) + :m_xUndoManager( i_undoManager ) +{ + ENSURE_OR_THROW( m_xUndoManager.is(), "invalid undo manager!" ); + m_xUndoManager->enterUndoContext( i_undoTitle ); +} + +//----------------------------------------------------------------------------- + +UndoContext::~UndoContext() +{ + m_xUndoManager->leaveUndoContext(); +} + +//----------------------------------------------------------------------------- + +HiddenUndoContext::HiddenUndoContext( const Reference< document::XUndoManager > & i_undoManager ) + :m_xUndoManager( i_undoManager ) +{ + ENSURE_OR_THROW( m_xUndoManager.is(), "invalid undo manager!" ); + try + { + m_xUndoManager->enterHiddenUndoContext(); + } + catch( const uno::Exception& ) { - Sequence< beans::PropertyValue > aArgs(1); - aArgs[0] = beans::PropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM("WithSelection")), -1, uno::Any(), - beans::PropertyState_DIRECT_VALUE ); - m_xUndoManager->preActionWithArguments( m_xModel, aArgs ); + DBG_UNHANDLED_EXCEPTION(); + m_xUndoManager.clear(); + // prevents the leaveUndoContext in the dtor } } -UndoGuardWithSelection::~UndoGuardWithSelection() +//----------------------------------------------------------------------------- + +HiddenUndoContext::~HiddenUndoContext() { - if( !m_bActionPosted && m_xUndoManager.is() ) - m_xUndoManager->cancelAction(); + try + { + if ( m_xUndoManager.is() ) + m_xUndoManager->leaveUndoContext(); + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } } } // namespace chart diff --git a/chart2/source/controller/main/UndoGuard.hxx b/chart2/source/controller/main/UndoGuard.hxx new file mode 100644 index 000000000000..c5c00dd62d1b --- /dev/null +++ b/chart2/source/controller/main/UndoGuard.hxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef CHART2_UNDOGUARD_HXX +#define CHART2_UNDOGUARD_HXX + +#include "ChartModelClone.hxx" + +#include <com/sun/star/document/XUndoManager.hpp> +#include <com/sun/star/frame/XModel.hpp> + +#include <rtl/ustring.hxx> + +#include <boost/shared_ptr.hpp> + +namespace chart +{ + +/** A guard which which does nothing, unless you explicitly call commitAction. In particular, in its destructor, it + does neither auto-commit nor auto-rollback the model changes. + */ +class UndoGuard +{ +public: + explicit UndoGuard( + const ::rtl::OUString& i_undoMessage, + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > & i_undoManager, + const ModelFacet i_facet = E_MODEL + ); + ~UndoGuard(); + + void commit(); + void rollback(); + +protected: + bool isActionPosted() const { return m_bActionPosted; } + +private: + void discardSnapshot(); + +private: + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xChartModel; + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > m_xUndoManager; + + ::boost::shared_ptr< ChartModelClone > m_pDocumentSnapshot; + rtl::OUString m_aUndoString; + bool m_bActionPosted; +}; + +/** A guard which, in its destructor, restores the model state it found in the constructor. If + <member>commitAction</member> is called inbetween, the restouration is not performed. + */ +class UndoLiveUpdateGuard : public UndoGuard +{ +public: + explicit UndoLiveUpdateGuard( + const ::rtl::OUString& i_undoMessage, + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > & i_undoManager + ); + ~UndoLiveUpdateGuard(); +}; + +/** Same as UndoLiveUpdateGuard but with additional storage of the chart's data. + Only use this if the data has internal data. + */ +class UndoLiveUpdateGuardWithData : + public UndoGuard +{ +public: + explicit UndoLiveUpdateGuardWithData( + const ::rtl::OUString& i_undoMessage, + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > & i_undoManager + ); + ~UndoLiveUpdateGuardWithData(); +}; + +class UndoGuardWithSelection : public UndoGuard +{ +public: + explicit UndoGuardWithSelection( + const ::rtl::OUString& i_undoMessage, + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > & i_undoManager + ); + virtual ~UndoGuardWithSelection(); +}; + +class UndoContext +{ +public: + UndoContext( + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > & i_undoManager, + const ::rtl::OUString& i_undoTitle + ); + ~UndoContext(); + +private: + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > m_xUndoManager; +}; + +class HiddenUndoContext +{ +public: + HiddenUndoContext( + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > & i_undoManager + ); + ~HiddenUndoContext(); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::document::XUndoManager > m_xUndoManager; +}; + +} +// CHART2_UNDOGUARD_HXX +#endif diff --git a/chart2/source/controller/main/UndoManager.cxx b/chart2/source/controller/main/UndoManager.cxx deleted file mode 100644 index 21b3bbc1f725..000000000000 --- a/chart2/source/controller/main/UndoManager.cxx +++ /dev/null @@ -1,438 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_chart2.hxx" - -#include "UndoManager.hxx" -#include "ImplUndoManager.hxx" -#include "DisposeHelper.hxx" -#include "MutexContainer.hxx" -#include "macros.hxx" -#include "ChartViewHelper.hxx" - -#include <com/sun/star/util/XCloneable.hpp> -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/chart2/XChartDocument.hpp> - -#include <unotools/configitem.hxx> -#include <cppuhelper/compbase1.hxx> -#include <rtl/uuid.h> -#include <svx/svdundo.hxx> - -#include <functional> - -using namespace ::com::sun::star; - -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::rtl::OUString; - - -// -------------------------------------------------------------------------------- - -namespace chart -{ - -namespace impl -{ -typedef ::cppu::WeakComponentImplHelper1< - util::XModifyBroadcaster > - ModifyBroadcaster_Base; - -class ModifyBroadcaster : - public ::chart::MutexContainer, - public ModifyBroadcaster_Base -{ -public: - ModifyBroadcaster(); - - void fireEvent(); - -protected: - // ____ XModifyBroadcaster ____ - virtual void SAL_CALL addModifyListener( const Reference< util::XModifyListener >& xListener ) - throw (uno::RuntimeException); - virtual void SAL_CALL removeModifyListener( const Reference< util::XModifyListener >& xListener ) - throw (uno::RuntimeException); -}; - -ModifyBroadcaster::ModifyBroadcaster() : - ModifyBroadcaster_Base( m_aMutex ) -{} - -void SAL_CALL ModifyBroadcaster::addModifyListener( - const Reference< util::XModifyListener >& xListener ) - throw (uno::RuntimeException) -{ - rBHelper.addListener( ::getCppuType( & xListener ), xListener); -} - -void SAL_CALL ModifyBroadcaster::removeModifyListener( - const Reference< util::XModifyListener >& xListener ) - throw (uno::RuntimeException) -{ - rBHelper.removeListener( ::getCppuType( & xListener ), xListener ); -} - -void ModifyBroadcaster::fireEvent() -{ - ::cppu::OInterfaceContainerHelper* pIC = rBHelper.getContainer( - ::getCppuType((const uno::Reference< util::XModifyListener >*)0) ); - if( pIC ) - { - lang::EventObject aEvent( static_cast< lang::XComponent* >( this ) ); - ::cppu::OInterfaceIteratorHelper aIt( *pIC ); - while( aIt.hasMoreElements() ) - { - uno::Reference< util::XModifyListener > xListener( aIt.next(), uno::UNO_QUERY ); - if( xListener.is() ) - xListener->modified( aEvent ); - } - } -} - -} // namespace impl - -UndoManager::UndoManager() : - impl::UndoManager_Base( m_aMutex ), - m_apUndoStack( new impl::UndoStack()), - m_apRedoStack( new impl::UndoStack()), - m_pLastRemeberedUndoElement( 0 ), - m_nMaxNumberOfUndos( 100 ), - m_pModifyBroadcaster( 0 ) -{} - -UndoManager::~UndoManager() -{ - DisposeHelper::Dispose( m_xModifyBroadcaster ); - m_apUndoStack->disposeAndClear(); - m_apRedoStack->disposeAndClear(); - - delete m_pLastRemeberedUndoElement; - m_pLastRemeberedUndoElement = 0; -} - -void UndoManager::addShapeUndoAction( SdrUndoAction* pAction ) -{ - if ( !pAction ) - { - return; - } - - impl::ShapeUndoElement* pShapeUndoElement = new impl::ShapeUndoElement( pAction->GetComment(), pAction ); - if ( pShapeUndoElement ) - { - m_apUndoStack->push( pShapeUndoElement ); - m_apRedoStack->disposeAndClear(); - if ( !m_apUndoStepsConfigItem.get() ) - { - retrieveConfigUndoSteps(); - } - fireModifyEvent(); - } -} - -void UndoManager::impl_undoRedo( - Reference< frame::XModel > & xCurrentModel, - impl::UndoStack * pStackToRemoveFrom, - impl::UndoStack * pStackToAddTo, - bool bUndo ) -{ - if( pStackToRemoveFrom && ! pStackToRemoveFrom->empty() ) - { - // get model from undo/redo - impl::UndoElement * pTop( pStackToRemoveFrom->top()); - if( pTop ) - { - impl::ShapeUndoElement* pShapeUndoElement = dynamic_cast< impl::ShapeUndoElement* >( pTop ); - if ( pShapeUndoElement ) - { - impl::ShapeUndoElement* pNewShapeUndoElement = new impl::ShapeUndoElement( *pShapeUndoElement ); - pStackToAddTo->push( pNewShapeUndoElement ); - SdrUndoAction* pAction = pNewShapeUndoElement->getSdrUndoAction(); - if ( pAction ) - { - if ( bUndo ) - { - pAction->Undo(); - } - else - { - pAction->Redo(); - } - } - } - else - { - // put a clone of current model into redo/undo stack with the same - // action string as the undo/redo - pStackToAddTo->push( pTop->createFromModel( xCurrentModel )); - // change current model by properties of the model from undo - pTop->applyToModel( xCurrentModel ); - } - // remove the top undo element - pStackToRemoveFrom->pop(), pTop = 0; - ChartViewHelper::setViewToDirtyState( xCurrentModel ); - fireModifyEvent(); - } - } - else - { - OSL_ENSURE( false, "Can't Undo/Redo" ); - } -} - -void UndoManager::fireModifyEvent() -{ - if( m_xModifyBroadcaster.is()) - m_pModifyBroadcaster->fireEvent(); -} - - -// ____ ConfigItemListener ____ -void UndoManager::notify( const ::rtl::OUString & rPropertyName ) -{ - OSL_ENSURE( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Steps" )), - "Unwanted config property change Notified" ); - if( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Steps" ))) - retrieveConfigUndoSteps(); -} - -void UndoManager::retrieveConfigUndoSteps() -{ - if( ! m_apUndoStepsConfigItem.get()) - m_apUndoStepsConfigItem.reset( new impl::UndoStepsConfigItem( *this )); - m_nMaxNumberOfUndos = m_apUndoStepsConfigItem->getUndoSteps(); - m_apUndoStack->limitSize( m_nMaxNumberOfUndos ); - m_apRedoStack->limitSize( m_nMaxNumberOfUndos ); - - // a list of available undo steps could shrink here - fireModifyEvent(); -} - -// ____ XModifyBroadcaster ____ -void SAL_CALL UndoManager::addModifyListener( const Reference< util::XModifyListener >& aListener ) - throw (uno::RuntimeException) -{ - if( ! m_xModifyBroadcaster.is()) - { - m_pModifyBroadcaster = new impl::ModifyBroadcaster(); - m_xModifyBroadcaster.set( static_cast< cppu::OWeakObject* >( m_pModifyBroadcaster ), uno::UNO_QUERY ); - } - m_xModifyBroadcaster->addModifyListener( aListener ); -} - -void SAL_CALL UndoManager::removeModifyListener( const Reference< util::XModifyListener >& aListener ) - throw (uno::RuntimeException) -{ - if( ! m_xModifyBroadcaster.is()) - { - m_pModifyBroadcaster = new impl::ModifyBroadcaster(); - m_xModifyBroadcaster.set( static_cast< cppu::OWeakObject* >( m_pModifyBroadcaster ), uno::UNO_QUERY ); - } - m_xModifyBroadcaster->removeModifyListener( aListener ); -} - -// ____ chart2::XUndoManager ____ -void SAL_CALL UndoManager::preAction( const Reference< frame::XModel >& xModelBeforeChange ) - throw (uno::RuntimeException) -{ - OSL_ENSURE( ! m_pLastRemeberedUndoElement, "Looks like postAction or cancelAction call was missing" ); - m_pLastRemeberedUndoElement = new impl::UndoElement( xModelBeforeChange ); -} - -void SAL_CALL UndoManager::preActionWithArguments( - const Reference< frame::XModel >& xModelBeforeChange, - const Sequence< beans::PropertyValue >& aArguments ) - throw (uno::RuntimeException) -{ - bool bActionHandled( false ); - OSL_ENSURE( ! m_pLastRemeberedUndoElement, "Looks like postAction or cancelAction call was missing" ); - if( aArguments.getLength() > 0 ) - { - OSL_ENSURE( aArguments.getLength() == 1, "More than one argument is not supported yet" ); - if( aArguments[0].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("WithData"))) - { - m_pLastRemeberedUndoElement = new impl::UndoElementWithData( xModelBeforeChange ); - bActionHandled = true; - } - else if( aArguments[0].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("WithSelection"))) - { - m_pLastRemeberedUndoElement = new impl::UndoElementWithSelection( xModelBeforeChange ); - bActionHandled = true; - } - } - - if( !bActionHandled ) - preAction( xModelBeforeChange ); -} - -void SAL_CALL UndoManager::postAction( const OUString& aUndoText ) - throw (uno::RuntimeException) -{ - OSL_ENSURE( m_pLastRemeberedUndoElement, "Looks like preAction call was missing" ); - if( m_pLastRemeberedUndoElement ) - { - m_pLastRemeberedUndoElement->setActionString( aUndoText ); - m_apUndoStack->push( m_pLastRemeberedUndoElement ); - m_pLastRemeberedUndoElement = 0; - - // redo no longer possible - m_apRedoStack->disposeAndClear(); - - // it suffices to get the number of undo steps from config after the - // first time postAction has been called - if( ! m_apUndoStepsConfigItem.get()) - retrieveConfigUndoSteps(); - - fireModifyEvent(); - } -} - -void SAL_CALL UndoManager::cancelAction() - throw (uno::RuntimeException) -{ - delete m_pLastRemeberedUndoElement; - m_pLastRemeberedUndoElement = 0; -} - -void SAL_CALL UndoManager::cancelActionWithUndo( Reference< frame::XModel >& xModelToRestore ) - throw (uno::RuntimeException) -{ - if( m_pLastRemeberedUndoElement ) - { - m_pLastRemeberedUndoElement->applyToModel( xModelToRestore ); - cancelAction(); - } -} - -void SAL_CALL UndoManager::undo( Reference< frame::XModel >& xCurrentModel ) - throw (uno::RuntimeException) -{ - OSL_ASSERT( m_apUndoStack.get() && m_apRedoStack.get()); - impl_undoRedo( xCurrentModel, m_apUndoStack.get(), m_apRedoStack.get(), true ); -} - -void SAL_CALL UndoManager::redo( Reference< frame::XModel >& xCurrentModel ) - throw (uno::RuntimeException) -{ - OSL_ASSERT( m_apUndoStack.get() && m_apRedoStack.get()); - impl_undoRedo( xCurrentModel, m_apRedoStack.get(), m_apUndoStack.get(), false ); -} - -::sal_Bool SAL_CALL UndoManager::undoPossible() - throw (uno::RuntimeException) -{ - return ! m_apUndoStack->empty(); -} - -::sal_Bool SAL_CALL UndoManager::redoPossible() - throw (uno::RuntimeException) -{ - return ! m_apRedoStack->empty(); -} - -OUString SAL_CALL UndoManager::getCurrentUndoString() - throw (uno::RuntimeException) -{ - return m_apUndoStack->topUndoString(); -} - -OUString SAL_CALL UndoManager::getCurrentRedoString() - throw (uno::RuntimeException) -{ - return m_apRedoStack->topUndoString(); -} - -Sequence< OUString > SAL_CALL UndoManager::getAllUndoStrings() - throw (uno::RuntimeException) -{ - return m_apUndoStack->getUndoStrings(); -} - -Sequence< OUString > SAL_CALL UndoManager::getAllRedoStrings() - throw (uno::RuntimeException) -{ - return m_apRedoStack->getUndoStrings(); -} - -// ____ XUndoHelper ____ -Reference< frame::XModel > SAL_CALL UndoManager::getModelCloneForUndo( - const Reference< frame::XModel >& xModelBeforeChange ) - throw (uno::RuntimeException) -{ - return impl::UndoElement::cloneModel( xModelBeforeChange ); -} - -void SAL_CALL UndoManager::applyModelContent( - Reference< frame::XModel >& xModelToChange, - const Reference< frame::XModel >& xModelToCopyFrom ) - throw (uno::RuntimeException) -{ - impl::UndoElement::applyModelContentToModel( xModelToChange, xModelToCopyFrom ); -} - -// ____ XUnoTunnel ____ -sal_Int64 UndoManager::getSomething( const Sequence< sal_Int8 >& rId ) - throw (uno::RuntimeException) -{ - if ( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) - { - return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ) ); - } - return 0; -} - -const Sequence< sal_Int8 >& UndoManager::getUnoTunnelId() -{ - static Sequence< sal_Int8 >* pSeq = 0; - if( !pSeq ) - { - osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); - if( !pSeq ) - { - static Sequence< sal_Int8 > aSeq( 16 ); - rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); - pSeq = &aSeq; - } - } - return *pSeq; -} - -UndoManager* UndoManager::getImplementation( const Reference< uno::XInterface > xObj ) -{ - UndoManager* pRet = NULL; - Reference< lang::XUnoTunnel > xUT( xObj, uno::UNO_QUERY ); - if ( xUT.is() ) - { - pRet = reinterpret_cast< UndoManager* >( sal::static_int_cast< sal_IntPtr >( xUT->getSomething( getUnoTunnelId() ) ) ); - } - return pRet; -} - -} // namespace chart diff --git a/chart2/source/controller/main/makefile.mk b/chart2/source/controller/main/makefile.mk index 729276d5bd0e..557d6cf6216f 100644 --- a/chart2/source/controller/main/makefile.mk +++ b/chart2/source/controller/main/makefile.mk @@ -72,12 +72,9 @@ SLOFILES = \ $(SLO)$/DrawCommandDispatch.obj \ $(SLO)$/ShapeController.obj \ $(SLO)$/ShapeToolbarController.obj \ - $(SLO)$/ImplUndoManager.obj \ - $(SLO)$/UndoManager.obj \ - $(SLO)$/UndoGuard.obj - -# $(SLO)$/CommonConverters.obj \ -# $(SLO)$/Scaling.obj \ + $(SLO)$/UndoActions.obj \ + $(SLO)$/UndoGuard.obj \ + $(SLO)$/ChartModelClone.obj \ # --- Targets ----------------------------------------------------------------- |