1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 #ifndef INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX 20 #define INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX 21 22 #include "dllapi.h" 23 24 #include "RptModel.hxx" 25 26 #include <com/sun/star/util/XModifyListener.hpp> 27 #include <com/sun/star/beans/XPropertySet.hpp> 28 #include <com/sun/star/beans/PropertyChangeEvent.hpp> 29 #include <com/sun/star/container/XNameContainer.hpp> 30 #include <com/sun/star/container/ContainerEvent.hpp> 31 #include <com/sun/star/report/XReportDefinition.hpp> 32 #include <com/sun/star/report/XGroup.hpp> 33 #include <com/sun/star/document/XUndoManager.hpp> 34 35 #include <svl/lstner.hxx> 36 #include <svx/svdouno.hxx> 37 #include <svx/svdundo.hxx> 38 39 #include <functional> 40 41 namespace dbaui 42 { 43 class IController; 44 } 45 namespace rptui 46 { 47 enum Action 48 { 49 Inserted = 1, 50 Removed = 2 51 }; 52 53 /** Helper class to allow std::mem_fun for SAL_CALL 54 */ 55 class REPORTDESIGN_DLLPUBLIC OGroupHelper 56 { 57 css::uno::Reference< css::report::XGroup > m_xGroup; 58 OGroupHelper(const OGroupHelper&) = delete; 59 OGroupHelper& operator=(const OGroupHelper&) = delete; 60 public: OGroupHelper(const css::uno::Reference<css::report::XGroup> & _xGroup)61 OGroupHelper(const css::uno::Reference< css::report::XGroup >& _xGroup) 62 :m_xGroup(_xGroup) 63 { 64 } getHeader()65 css::uno::Reference< css::report::XSection > getHeader() { return m_xGroup->getHeader(); } getFooter()66 css::uno::Reference< css::report::XSection > getFooter() { return m_xGroup->getFooter(); } getGroup() const67 const css::uno::Reference< css::report::XGroup >& getGroup() const { return m_xGroup; } 68 getHeaderOn()69 bool getHeaderOn() { return m_xGroup->getHeaderOn(); } getFooterOn()70 bool getFooterOn() { return m_xGroup->getFooterOn(); } 71 72 static ::std::function<css::uno::Reference< css::report::XSection>(OGroupHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection); 73 74 }; 75 76 /** Helper class to allow std::mem_fun for SAL_CALL 77 */ 78 class REPORTDESIGN_DLLPUBLIC OReportHelper 79 { 80 css::uno::Reference< css::report::XReportDefinition > m_xReport; 81 public: OReportHelper(const css::uno::Reference<css::report::XReportDefinition> & _xReport)82 OReportHelper(const css::uno::Reference< css::report::XReportDefinition >& _xReport) 83 :m_xReport(_xReport) 84 { 85 } getReportHeader()86 css::uno::Reference< css::report::XSection > getReportHeader() { return m_xReport->getReportHeader(); } getReportFooter()87 css::uno::Reference< css::report::XSection > getReportFooter() { return m_xReport->getReportFooter(); } getPageHeader()88 css::uno::Reference< css::report::XSection > getPageHeader() { return m_xReport->getPageHeader(); } getPageFooter()89 css::uno::Reference< css::report::XSection > getPageFooter() { return m_xReport->getPageFooter(); } getDetail()90 css::uno::Reference< css::report::XSection > getDetail() { return m_xReport->getDetail(); } 91 getReportHeaderOn()92 bool getReportHeaderOn() { return m_xReport->getReportHeaderOn(); } getReportFooterOn()93 bool getReportFooterOn() { return m_xReport->getReportFooterOn(); } getPageHeaderOn()94 bool getPageHeaderOn() { return m_xReport->getPageHeaderOn(); } getPageFooterOn()95 bool getPageFooterOn() { return m_xReport->getPageFooterOn(); } 96 97 static ::std::function<css::uno::Reference< css::report::XSection>(OReportHelper *)> getMemberFunction(const css::uno::Reference< css::report::XSection >& _xSection); 98 }; 99 100 101 //= UndoContext 102 103 class UndoContext 104 { 105 public: UndoContext(SfxUndoManager & i_undoManager,const OUString & i_undoTitle)106 UndoContext( SfxUndoManager& i_undoManager, const OUString& i_undoTitle ) 107 :m_rUndoManager( i_undoManager ) 108 { 109 m_rUndoManager.EnterListAction( i_undoTitle, OUString(), 0, ViewShellId(-1) ); 110 } 111 ~UndoContext()112 ~UndoContext() 113 { 114 m_rUndoManager.LeaveListAction(); 115 } 116 117 private: 118 SfxUndoManager& m_rUndoManager; 119 }; 120 121 122 //= UndoSuppressor 123 124 class UndoSuppressor 125 { 126 public: UndoSuppressor(SfxUndoManager & i_undoManager)127 UndoSuppressor( SfxUndoManager& i_undoManager ) 128 :m_rUndoManager( i_undoManager ) 129 { 130 m_rUndoManager.EnableUndo( false ); 131 } 132 ~UndoSuppressor()133 ~UndoSuppressor() 134 { 135 m_rUndoManager.EnableUndo( true ); 136 } 137 138 private: 139 SfxUndoManager& m_rUndoManager; 140 }; 141 142 143 //= OCommentUndoAction 144 145 class REPORTDESIGN_DLLPUBLIC OCommentUndoAction : public SdrUndoAction 146 { 147 protected: 148 OUString m_strComment; // undo, redo comment 149 ::dbaui::IController* m_pController; 150 151 public: 152 OCommentUndoAction(SdrModel& rMod, const char* pCommentID); 153 virtual ~OCommentUndoAction() override; 154 GetComment() const155 virtual OUString GetComment() const override { return m_strComment; } 156 virtual void Undo() override; 157 virtual void Redo() override; 158 }; 159 160 // OUndoContainerAction 161 162 class REPORTDESIGN_DLLPUBLIC OUndoContainerAction: public OCommentUndoAction 163 { 164 OUndoContainerAction(OUndoContainerAction const &) = delete; 165 void operator =(OUndoContainerAction const &) = delete; 166 protected: 167 css::uno::Reference< css::uno::XInterface > 168 m_xElement; // object not owned by the action 169 css::uno::Reference< css::uno::XInterface > 170 m_xOwnElement; // object owned by the action 171 css::uno::Reference< css::container::XIndexContainer > 172 m_xContainer; 173 Action const m_eAction; 174 175 public: 176 OUndoContainerAction(SdrModel& rMod 177 ,Action _eAction 178 ,const css::uno::Reference< css::container::XIndexContainer >& rContainer 179 ,const css::uno::Reference< css::uno::XInterface>& xElem 180 ,const char* pCommentId); 181 virtual ~OUndoContainerAction() override; 182 183 virtual void Undo() override; 184 virtual void Redo() override; 185 186 protected: 187 virtual void implReInsert( ); 188 virtual void implReRemove( ); 189 }; 190 191 192 // OUndoReportSectionAction 193 194 class REPORTDESIGN_DLLPUBLIC OUndoReportSectionAction : public OUndoContainerAction 195 { 196 OReportHelper m_aReportHelper; 197 ::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction; 198 public: 199 OUndoReportSectionAction(SdrModel& rMod 200 ,Action _eAction 201 ,::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction 202 ,const css::uno::Reference< css::report::XReportDefinition >& _xReport 203 ,const css::uno::Reference< css::uno::XInterface>& xElem 204 ,const char* pCommentId); 205 206 protected: 207 virtual void implReInsert( ) override; 208 virtual void implReRemove( ) override; 209 }; 210 211 212 // OUndoGroupSectionAction 213 class REPORTDESIGN_DLLPUBLIC OUndoGroupSectionAction : public OUndoContainerAction 214 { 215 OGroupHelper m_aGroupHelper; 216 ::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction; 217 public: 218 OUndoGroupSectionAction(SdrModel& rMod 219 ,Action _eAction 220 ,::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction 221 ,const css::uno::Reference< css::report::XGroup >& _xGroup 222 ,const css::uno::Reference< css::uno::XInterface>& xElem 223 ,const char* pCommentId); 224 225 protected: 226 virtual void implReInsert( ) override; 227 virtual void implReRemove( ) override; 228 }; 229 230 // ORptUndoPropertyAction 231 class REPORTDESIGN_DLLPUBLIC ORptUndoPropertyAction: public OCommentUndoAction 232 { 233 css::uno::Reference< css::beans::XPropertySet> m_xObj; 234 OUString const m_aPropertyName; 235 css::uno::Any const m_aNewValue; 236 css::uno::Any const m_aOldValue; 237 238 /** sets either the old value or the new value again at the property set. 239 * 240 * \param _bOld If set to <TRUE/> than the old value will be set otherwise the new value will be set. 241 */ 242 void setProperty(bool _bOld); 243 protected: 244 virtual css::uno::Reference< css::beans::XPropertySet> getObject(); 245 246 public: 247 ORptUndoPropertyAction(SdrModel& rMod, const css::beans::PropertyChangeEvent& evt); 248 249 virtual void Undo() override; 250 virtual void Redo() override; 251 252 virtual OUString GetComment() const override; 253 }; 254 255 256 // OUndoPropertyReportSectionAction 257 258 class REPORTDESIGN_DLLPUBLIC OUndoPropertyReportSectionAction : public ORptUndoPropertyAction 259 { 260 OReportHelper m_aReportHelper; 261 ::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> m_pMemberFunction; 262 protected: 263 virtual css::uno::Reference< css::beans::XPropertySet> getObject() override; 264 public: 265 OUndoPropertyReportSectionAction(SdrModel& rMod 266 ,const css::beans::PropertyChangeEvent& evt 267 ,::std::function<css::uno::Reference< css::report::XSection >(OReportHelper *)> _pMemberFunction 268 ,const css::uno::Reference< css::report::XReportDefinition >& _xReport 269 ); 270 }; 271 272 273 // OUndoPropertyGroupSectionAction 274 275 class REPORTDESIGN_DLLPUBLIC OUndoPropertyGroupSectionAction : public ORptUndoPropertyAction 276 { 277 OGroupHelper m_aGroupHelper; 278 ::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> m_pMemberFunction; 279 protected: 280 virtual css::uno::Reference< css::beans::XPropertySet> getObject() override; 281 public: 282 OUndoPropertyGroupSectionAction(SdrModel& rMod 283 ,const css::beans::PropertyChangeEvent& evt 284 ,::std::function<css::uno::Reference< css::report::XSection >(OGroupHelper *)> _pMemberFunction 285 ,const css::uno::Reference< css::report::XGroup >& _xGroup 286 ); 287 }; 288 289 } 290 #endif // INCLUDED_REPORTDESIGN_INC_UNDOACTIONS_HXX 291 292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 293