Line data Source code
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 :
20 : #include "dbaundomanager.hxx"
21 : #include "singledoccontroller.hxx"
22 : #include "browserids.hxx"
23 : #include "dbu_misc.hrc"
24 : #include "dbustrings.hrc"
25 : #include "moduledbu.hxx"
26 :
27 : #include <svl/undo.hxx>
28 : #include <osl/diagnose.h>
29 :
30 : #include <boost/scoped_ptr.hpp>
31 :
32 : //......................................................................................................................
33 : namespace dbaui
34 : {
35 : //......................................................................................................................
36 :
37 : /** === begin UNO using === **/
38 : using ::com::sun::star::uno::Reference;
39 : using ::com::sun::star::uno::XInterface;
40 : using ::com::sun::star::uno::UNO_QUERY;
41 : using ::com::sun::star::uno::UNO_QUERY_THROW;
42 : using ::com::sun::star::uno::UNO_SET_THROW;
43 : using ::com::sun::star::uno::Exception;
44 : using ::com::sun::star::uno::RuntimeException;
45 : using ::com::sun::star::uno::Any;
46 : using ::com::sun::star::uno::makeAny;
47 : using ::com::sun::star::uno::Sequence;
48 : using ::com::sun::star::uno::Type;
49 : using ::com::sun::star::document::XUndoManager;
50 : using ::com::sun::star::lang::XMultiServiceFactory;
51 : using ::com::sun::star::beans::PropertyValue;
52 : using ::com::sun::star::lang::EventObject;
53 : /** === end UNO using === **/
54 :
55 : //==================================================================================================================
56 : //= OSingleDocumentController_Data
57 : //==================================================================================================================
58 0 : struct OSingleDocumentController_Data
59 : {
60 : ::boost::scoped_ptr< UndoManager > m_pUndoManager;
61 :
62 0 : OSingleDocumentController_Data( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
63 0 : :m_pUndoManager( new UndoManager( i_parent, i_mutex ) )
64 : {
65 0 : }
66 : };
67 :
68 : //==================================================================================================================
69 : //= OSingleDocumentController
70 : //==================================================================================================================
71 : //------------------------------------------------------------------------------------------------------------------
72 0 : OSingleDocumentController::OSingleDocumentController( const Reference< XMultiServiceFactory >& _rxORB )
73 : :OSingleDocumentController_Base( _rxORB )
74 0 : ,m_pData( new OSingleDocumentController_Data( *this, getMutex() ) )
75 : {
76 0 : }
77 :
78 : //------------------------------------------------------------------------------------------------------------------
79 0 : OSingleDocumentController::~OSingleDocumentController()
80 : {
81 0 : }
82 :
83 : // -----------------------------------------------------------------------------
84 0 : void SAL_CALL OSingleDocumentController::disposing()
85 : {
86 0 : OSingleDocumentController_Base::disposing();
87 0 : ClearUndoManager();
88 0 : m_pData->m_pUndoManager->disposing();
89 0 : }
90 :
91 : // -----------------------------------------------------------------------------
92 0 : void SAL_CALL OSingleDocumentController::disposing( const EventObject& i_event ) throw( RuntimeException )
93 : {
94 : // simply disambiguate
95 0 : OSingleDocumentController_Base::disposing( i_event );
96 0 : }
97 :
98 : // -----------------------------------------------------------------------------
99 0 : void OSingleDocumentController::ClearUndoManager()
100 : {
101 0 : GetUndoManager().Clear();
102 0 : }
103 :
104 : // -----------------------------------------------------------------------------
105 0 : SfxUndoManager& OSingleDocumentController::GetUndoManager() const
106 : {
107 0 : return m_pData->m_pUndoManager->GetSfxUndoManager();
108 : }
109 :
110 : // -----------------------------------------------------------------------------
111 0 : void OSingleDocumentController::addUndoActionAndInvalidate(SfxUndoAction *_pAction)
112 : {
113 : // add undo action
114 0 : GetUndoManager().AddUndoAction( _pAction );
115 :
116 : // when we add an undo action the controller was modified
117 0 : setModified( sal_True );
118 :
119 : // now inform me that or states changed
120 0 : InvalidateFeature( ID_BROWSER_UNDO );
121 0 : InvalidateFeature( ID_BROWSER_REDO );
122 0 : }
123 :
124 : // -----------------------------------------------------------------------------
125 0 : Reference< XUndoManager > SAL_CALL OSingleDocumentController::getUndoManager( ) throw (RuntimeException)
126 : {
127 0 : return m_pData->m_pUndoManager.get();
128 : }
129 :
130 : // -----------------------------------------------------------------------------
131 0 : FeatureState OSingleDocumentController::GetState(sal_uInt16 _nId) const
132 : {
133 0 : FeatureState aReturn;
134 0 : switch ( _nId )
135 : {
136 : case ID_BROWSER_UNDO:
137 0 : aReturn.bEnabled = isEditable() && GetUndoManager().GetUndoActionCount() != 0;
138 0 : if ( aReturn.bEnabled )
139 : {
140 0 : String sUndo(ModuleRes(STR_UNDO_COLON));
141 0 : sUndo += String(RTL_CONSTASCII_USTRINGPARAM(" "));
142 0 : sUndo += GetUndoManager().GetUndoActionComment();
143 0 : aReturn.sTitle = sUndo;
144 : }
145 0 : break;
146 :
147 : case ID_BROWSER_REDO:
148 0 : aReturn.bEnabled = isEditable() && GetUndoManager().GetRedoActionCount() != 0;
149 0 : if ( aReturn.bEnabled )
150 : {
151 0 : String sRedo(ModuleRes(STR_REDO_COLON));
152 0 : sRedo += String(RTL_CONSTASCII_USTRINGPARAM(" "));
153 0 : sRedo += GetUndoManager().GetRedoActionComment();
154 0 : aReturn.sTitle = sRedo;
155 : }
156 0 : break;
157 :
158 : default:
159 0 : aReturn = OSingleDocumentController_Base::GetState(_nId);
160 : }
161 0 : return aReturn;
162 : }
163 : // -----------------------------------------------------------------------------
164 0 : void OSingleDocumentController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue >& _rArgs )
165 : {
166 0 : switch ( _nId )
167 : {
168 : case ID_BROWSER_UNDO:
169 0 : GetUndoManager().Undo();
170 0 : InvalidateFeature( ID_BROWSER_UNDO );
171 0 : InvalidateFeature( ID_BROWSER_REDO );
172 0 : break;
173 :
174 : case ID_BROWSER_REDO:
175 0 : GetUndoManager().Redo();
176 0 : InvalidateFeature( ID_BROWSER_UNDO );
177 0 : InvalidateFeature( ID_BROWSER_REDO );
178 0 : break;
179 :
180 : default:
181 0 : OSingleDocumentController_Base::Execute( _nId, _rArgs );
182 0 : break;
183 : }
184 0 : InvalidateFeature(_nId);
185 0 : }
186 :
187 : //......................................................................................................................
188 : } // namespace dbaui
189 : //......................................................................................................................
190 :
191 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|