1*9ee13d13SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9ee13d13SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9ee13d13SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9ee13d13SAndrew Rist * distributed with this work for additional information 6*9ee13d13SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9ee13d13SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9ee13d13SAndrew Rist * "License"); you may not use this file except in compliance 9*9ee13d13SAndrew Rist * with the License. You may obtain a copy of the License at 10*9ee13d13SAndrew Rist * 11*9ee13d13SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9ee13d13SAndrew Rist * 13*9ee13d13SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9ee13d13SAndrew Rist * software distributed under the License is distributed on an 15*9ee13d13SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9ee13d13SAndrew Rist * KIND, either express or implied. See the License for the 17*9ee13d13SAndrew Rist * specific language governing permissions and limitations 18*9ee13d13SAndrew Rist * under the License. 19*9ee13d13SAndrew Rist * 20*9ee13d13SAndrew Rist *************************************************************/ 21*9ee13d13SAndrew Rist 22*9ee13d13SAndrew Rist 23cdf0e10cSrcweir #ifndef RPTUI_UNDOACTIONS_HXX 24cdf0e10cSrcweir #define RPTUI_UNDOACTIONS_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "dllapi.h" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "RptModel.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir /** === begin UNO includes === **/ 31cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp> 32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyChangeEvent.hpp> 34cdf0e10cSrcweir #include <com/sun/star/script/ScriptEvent.hpp> 35cdf0e10cSrcweir #include <com/sun/star/script/XScriptListener.hpp> 36cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp> 37cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 38cdf0e10cSrcweir #include <com/sun/star/container/ContainerEvent.hpp> 39cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 40cdf0e10cSrcweir #include <com/sun/star/report/XReportComponent.hpp> 41cdf0e10cSrcweir #include <com/sun/star/report/XReportDefinition.hpp> 42cdf0e10cSrcweir #include <com/sun/star/report/XGroup.hpp> 43cdf0e10cSrcweir #include <com/sun/star/document/XUndoManager.hpp> 44cdf0e10cSrcweir /** === end UNO includes === **/ 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 47cdf0e10cSrcweir #include <comphelper/uno3.hxx> 48cdf0e10cSrcweir #include <comphelper/sequence.hxx> 49cdf0e10cSrcweir #include <svl/lstner.hxx> 50cdf0e10cSrcweir #include <svx/svdouno.hxx> 51cdf0e10cSrcweir #include <svx/svdundo.hxx> 52cdf0e10cSrcweir #include <tools/string.hxx> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <functional> 55cdf0e10cSrcweir #include <memory> 56cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 57cdf0e10cSrcweir 58cdf0e10cSrcweir FORWARD_DECLARE_INTERFACE(awt,XControl) 59cdf0e10cSrcweir FORWARD_DECLARE_INTERFACE(awt,XControlContainer) 60cdf0e10cSrcweir namespace dbaui 61cdf0e10cSrcweir { 62cdf0e10cSrcweir class IController; 63cdf0e10cSrcweir } 64cdf0e10cSrcweir namespace rptui 65cdf0e10cSrcweir { 66cdf0e10cSrcweir class OObjectBase; 67cdf0e10cSrcweir 68cdf0e10cSrcweir enum Action 69cdf0e10cSrcweir { 70cdf0e10cSrcweir Inserted = 1, 71cdf0e10cSrcweir Removed = 2 72cdf0e10cSrcweir }; 73cdf0e10cSrcweir 74cdf0e10cSrcweir /** Helper class to allow std::mem_fun for SAL_CALL 75cdf0e10cSrcweir */ 76cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OGroupHelper 77cdf0e10cSrcweir { 78cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup > m_xGroup; 79cdf0e10cSrcweir OGroupHelper(const OGroupHelper&); 80cdf0e10cSrcweir OGroupHelper& operator=(const OGroupHelper&); 81cdf0e10cSrcweir public: OGroupHelper(const::com::sun::star::uno::Reference<::com::sun::star::report::XGroup> & _xGroup)82cdf0e10cSrcweir OGroupHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup) 83cdf0e10cSrcweir :m_xGroup(_xGroup) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir } getHeader()86cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getHeader() { return m_xGroup->getHeader(); } getFooter()87cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getFooter() { return m_xGroup->getFooter(); } getGroup()88cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup > getGroup() { return m_xGroup; } 89cdf0e10cSrcweir getHeaderOn()90cdf0e10cSrcweir inline ::sal_Bool getHeaderOn() { return m_xGroup->getHeaderOn(); } getFooterOn()91cdf0e10cSrcweir inline ::sal_Bool getFooterOn() { return m_xGroup->getFooterOn(); } 92cdf0e10cSrcweir 93cdf0e10cSrcweir static ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> , OGroupHelper> getMemberFunction(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection); 94cdf0e10cSrcweir 95cdf0e10cSrcweir }; 96cdf0e10cSrcweir typedef com::sun::star::uno::Reference< ::com::sun::star::report::XSection > TSection; 97cdf0e10cSrcweir 98cdf0e10cSrcweir /** Helper class to allow std::mem_fun for SAL_CALL 99cdf0e10cSrcweir */ 100cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OReportHelper 101cdf0e10cSrcweir { 102cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition > m_xReport; 103cdf0e10cSrcweir public: OReportHelper(const::com::sun::star::uno::Reference<::com::sun::star::report::XReportDefinition> & _xReport)104cdf0e10cSrcweir OReportHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport) 105cdf0e10cSrcweir :m_xReport(_xReport) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir } getReportHeader()108cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); } getReportFooter()109cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); } getPageHeader()110cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getPageHeader() { return m_xReport->getPageHeader(); } getPageFooter()111cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getPageFooter() { return m_xReport->getPageFooter(); } getDetail()112cdf0e10cSrcweir inline ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > getDetail() { return m_xReport->getDetail(); } 113cdf0e10cSrcweir getReportHeaderOn()114cdf0e10cSrcweir inline ::sal_Bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); } getReportFooterOn()115cdf0e10cSrcweir inline ::sal_Bool getReportFooterOn() { return m_xReport->getReportFooterOn(); } getPageHeaderOn()116cdf0e10cSrcweir inline ::sal_Bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); } getPageFooterOn()117cdf0e10cSrcweir inline ::sal_Bool getPageFooterOn() { return m_xReport->getPageFooterOn(); } 118cdf0e10cSrcweir 119cdf0e10cSrcweir static ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> , OReportHelper> getMemberFunction(const ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection >& _xSection); 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir //================================================================================================================== 123cdf0e10cSrcweir //= UndoContext 124cdf0e10cSrcweir //================================================================================================================== 125cdf0e10cSrcweir class UndoContext 126cdf0e10cSrcweir { 127cdf0e10cSrcweir public: UndoContext(SfxUndoManager & i_undoManager,const::rtl::OUString & i_undoTitle)128cdf0e10cSrcweir UndoContext( SfxUndoManager& i_undoManager, const ::rtl::OUString& i_undoTitle ) 129cdf0e10cSrcweir :m_rUndoManager( i_undoManager ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir m_rUndoManager.EnterListAction( i_undoTitle, String() ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir ~UndoContext()134cdf0e10cSrcweir ~UndoContext() 135cdf0e10cSrcweir { 136cdf0e10cSrcweir m_rUndoManager.LeaveListAction(); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir private: 140cdf0e10cSrcweir SfxUndoManager& m_rUndoManager; 141cdf0e10cSrcweir }; 142cdf0e10cSrcweir 143cdf0e10cSrcweir //================================================================================================================== 144cdf0e10cSrcweir //= UndoSuppressor 145cdf0e10cSrcweir //================================================================================================================== 146cdf0e10cSrcweir class UndoSuppressor 147cdf0e10cSrcweir { 148cdf0e10cSrcweir public: UndoSuppressor(SfxUndoManager & i_undoManager)149cdf0e10cSrcweir UndoSuppressor( SfxUndoManager& i_undoManager ) 150cdf0e10cSrcweir :m_rUndoManager( i_undoManager ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir m_rUndoManager.EnableUndo( false ); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir ~UndoSuppressor()155cdf0e10cSrcweir ~UndoSuppressor() 156cdf0e10cSrcweir { 157cdf0e10cSrcweir m_rUndoManager.EnableUndo( true ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir private: 161cdf0e10cSrcweir SfxUndoManager& m_rUndoManager; 162cdf0e10cSrcweir }; 163cdf0e10cSrcweir 164cdf0e10cSrcweir //================================================================================================================== 165cdf0e10cSrcweir //= OCommentUndoAction 166cdf0e10cSrcweir //================================================================================================================== 167cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OCommentUndoAction : public SdrUndoAction 168cdf0e10cSrcweir { 169cdf0e10cSrcweir protected: 170cdf0e10cSrcweir String m_strComment; // undo, redo comment 171cdf0e10cSrcweir ::dbaui::IController* m_pController; 172cdf0e10cSrcweir 173cdf0e10cSrcweir public: 174cdf0e10cSrcweir TYPEINFO(); 175cdf0e10cSrcweir OCommentUndoAction( SdrModel& rMod 176cdf0e10cSrcweir ,sal_uInt16 nCommentID); 177cdf0e10cSrcweir virtual ~OCommentUndoAction(); 178cdf0e10cSrcweir GetComment() const179cdf0e10cSrcweir virtual UniString GetComment() const { return m_strComment; } 180cdf0e10cSrcweir virtual void Undo(); 181cdf0e10cSrcweir virtual void Redo(); 182cdf0e10cSrcweir }; 183cdf0e10cSrcweir //================================================================== 184cdf0e10cSrcweir // OUndoContainerAction 185cdf0e10cSrcweir //================================================================== 186cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OUndoContainerAction: public OCommentUndoAction 187cdf0e10cSrcweir { 188cdf0e10cSrcweir OUndoContainerAction(OUndoContainerAction&); 189cdf0e10cSrcweir void operator =(OUndoContainerAction&); 190cdf0e10cSrcweir protected: 191cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 192cdf0e10cSrcweir m_xElement; // object not owned by the action 193cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 194cdf0e10cSrcweir m_xOwnElement; // object owned by the action 195cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > 196cdf0e10cSrcweir m_xContainer; 197cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 198cdf0e10cSrcweir m_xSection; 199cdf0e10cSrcweir Action m_eAction; 200cdf0e10cSrcweir 201cdf0e10cSrcweir public: 202cdf0e10cSrcweir OUndoContainerAction(SdrModel& rMod 203cdf0e10cSrcweir ,Action _eAction 204cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > _xContainer 205cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem 206cdf0e10cSrcweir ,sal_uInt16 _nCommentId); 207cdf0e10cSrcweir virtual ~OUndoContainerAction(); 208cdf0e10cSrcweir 209cdf0e10cSrcweir virtual void Undo(); 210cdf0e10cSrcweir virtual void Redo(); 211cdf0e10cSrcweir 212cdf0e10cSrcweir protected: 213cdf0e10cSrcweir virtual void implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); 214cdf0e10cSrcweir virtual void implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); 215cdf0e10cSrcweir }; 216cdf0e10cSrcweir 217cdf0e10cSrcweir //================================================================== 218cdf0e10cSrcweir // OUndoReportSectionAction 219cdf0e10cSrcweir //================================================================== 220cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OUndoReportSectionAction : public OUndoContainerAction 221cdf0e10cSrcweir { 222cdf0e10cSrcweir OReportHelper m_aReportHelper; 223cdf0e10cSrcweir ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 224cdf0e10cSrcweir ,OReportHelper> m_pMemberFunction; 225cdf0e10cSrcweir public: 226cdf0e10cSrcweir OUndoReportSectionAction(SdrModel& rMod 227cdf0e10cSrcweir ,Action _eAction 228cdf0e10cSrcweir ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 229cdf0e10cSrcweir ,OReportHelper> _pMemberFunction 230cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport 231cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem 232cdf0e10cSrcweir ,sal_uInt16 _nCommentId); 233cdf0e10cSrcweir 234cdf0e10cSrcweir protected: 235cdf0e10cSrcweir virtual void implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); 236cdf0e10cSrcweir virtual void implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); 237cdf0e10cSrcweir }; 238cdf0e10cSrcweir 239cdf0e10cSrcweir //================================================================== 240cdf0e10cSrcweir // OUndoGroupSectionAction 241cdf0e10cSrcweir //================================================================== 242cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OUndoGroupSectionAction : public OUndoContainerAction 243cdf0e10cSrcweir { 244cdf0e10cSrcweir OGroupHelper m_aGroupHelper; 245cdf0e10cSrcweir ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 246cdf0e10cSrcweir ,OGroupHelper> m_pMemberFunction; 247cdf0e10cSrcweir public: 248cdf0e10cSrcweir OUndoGroupSectionAction(SdrModel& rMod 249cdf0e10cSrcweir ,Action _eAction 250cdf0e10cSrcweir ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 251cdf0e10cSrcweir ,OGroupHelper> _pMemberFunction 252cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup 253cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& xElem 254cdf0e10cSrcweir ,sal_uInt16 _nCommentId); 255cdf0e10cSrcweir 256cdf0e10cSrcweir protected: 257cdf0e10cSrcweir virtual void implReInsert( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); 258cdf0e10cSrcweir virtual void implReRemove( ) SAL_THROW( ( ::com::sun::star::uno::Exception ) ); 259cdf0e10cSrcweir }; 260cdf0e10cSrcweir 261cdf0e10cSrcweir ///================================================================== 262cdf0e10cSrcweir /// ORptUndoPropertyAction 263cdf0e10cSrcweir ///================================================================== 264cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC ORptUndoPropertyAction: public OCommentUndoAction 265cdf0e10cSrcweir { 266cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xObj; 267cdf0e10cSrcweir ::rtl::OUString m_aPropertyName; 268cdf0e10cSrcweir ::com::sun::star::uno::Any m_aNewValue; 269cdf0e10cSrcweir ::com::sun::star::uno::Any m_aOldValue; 270cdf0e10cSrcweir 271cdf0e10cSrcweir /** sets either the old value or the new value again at the property set. 272cdf0e10cSrcweir * 273cdf0e10cSrcweir * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set. 274cdf0e10cSrcweir */ 275cdf0e10cSrcweir void setProperty(sal_Bool _bOld); 276cdf0e10cSrcweir protected: 277cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject(); 278cdf0e10cSrcweir 279cdf0e10cSrcweir public: 280cdf0e10cSrcweir ORptUndoPropertyAction(SdrModel& rMod, const ::com::sun::star::beans::PropertyChangeEvent& evt); 281cdf0e10cSrcweir 282cdf0e10cSrcweir virtual void Undo(); 283cdf0e10cSrcweir virtual void Redo(); 284cdf0e10cSrcweir 285cdf0e10cSrcweir virtual String GetComment() const; 286cdf0e10cSrcweir }; 287cdf0e10cSrcweir 288cdf0e10cSrcweir //================================================================== 289cdf0e10cSrcweir // OUndoPropertyReportSectionAction 290cdf0e10cSrcweir //================================================================== 291cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OUndoPropertyReportSectionAction : public ORptUndoPropertyAction 292cdf0e10cSrcweir { 293cdf0e10cSrcweir OReportHelper m_aReportHelper; 294cdf0e10cSrcweir ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 295cdf0e10cSrcweir ,OReportHelper> m_pMemberFunction; 296cdf0e10cSrcweir protected: 297cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject(); 298cdf0e10cSrcweir public: 299cdf0e10cSrcweir OUndoPropertyReportSectionAction(SdrModel& rMod 300cdf0e10cSrcweir ,const ::com::sun::star::beans::PropertyChangeEvent& evt 301cdf0e10cSrcweir ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 302cdf0e10cSrcweir ,OReportHelper> _pMemberFunction 303cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportDefinition >& _xReport 304cdf0e10cSrcweir ); 305cdf0e10cSrcweir }; 306cdf0e10cSrcweir 307cdf0e10cSrcweir //================================================================== 308cdf0e10cSrcweir // OUndoPropertyGroupSectionAction 309cdf0e10cSrcweir //================================================================== 310cdf0e10cSrcweir class REPORTDESIGN_DLLPUBLIC OUndoPropertyGroupSectionAction : public ORptUndoPropertyAction 311cdf0e10cSrcweir { 312cdf0e10cSrcweir OGroupHelper m_aGroupHelper; 313cdf0e10cSrcweir ::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 314cdf0e10cSrcweir ,OGroupHelper> m_pMemberFunction; 315cdf0e10cSrcweir protected: 316cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getObject(); 317cdf0e10cSrcweir public: 318cdf0e10cSrcweir OUndoPropertyGroupSectionAction(SdrModel& rMod 319cdf0e10cSrcweir ,const ::com::sun::star::beans::PropertyChangeEvent& evt 320cdf0e10cSrcweir ,::std::mem_fun_t< ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection > 321cdf0e10cSrcweir ,OGroupHelper> _pMemberFunction 322cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::report::XGroup >& _xGroup 323cdf0e10cSrcweir ); 324cdf0e10cSrcweir }; 325cdf0e10cSrcweir 326cdf0e10cSrcweir } 327cdf0e10cSrcweir #endif //RPTUI_UNDOACTIONS_HXX 328cdf0e10cSrcweir 329