Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / misc / singledoccontroller.cxx
blob77408cdaf51adfa58c317fde8c4e676c9af464c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <dbaccess/dbaundomanager.hxx>
21 #include <dbaccess/dataview.hxx>
22 #include "singledoccontroller.hxx"
23 #include "browserids.hxx"
24 #include "dbu_misc.hrc"
25 #include "dbustrings.hrc"
26 #include "moduledbu.hxx"
28 #include <svl/undo.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <osl/diagnose.h>
32 #include <boost/scoped_ptr.hpp>
34 namespace dbaui
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::XInterface;
39 using ::com::sun::star::uno::UNO_QUERY;
40 using ::com::sun::star::uno::UNO_QUERY_THROW;
41 using ::com::sun::star::uno::UNO_SET_THROW;
42 using ::com::sun::star::uno::Exception;
43 using ::com::sun::star::uno::RuntimeException;
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::makeAny;
46 using ::com::sun::star::uno::Sequence;
47 using ::com::sun::star::uno::Type;
48 using ::com::sun::star::uno::XComponentContext;
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;
54 // OSingleDocumentController_Data
55 struct OSingleDocumentController_Data
57 ::boost::scoped_ptr< UndoManager > m_pUndoManager;
59 OSingleDocumentController_Data( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
60 :m_pUndoManager( new UndoManager( i_parent, i_mutex ) )
65 // OSingleDocumentController
66 OSingleDocumentController::OSingleDocumentController( const Reference< XComponentContext >& _rxORB )
67 :OSingleDocumentController_Base( _rxORB )
68 ,m_pData( new OSingleDocumentController_Data( *this, getMutex() ) )
72 OSingleDocumentController::~OSingleDocumentController()
76 void SAL_CALL OSingleDocumentController::disposing()
78 OSingleDocumentController_Base::disposing();
79 ClearUndoManager();
80 m_pData->m_pUndoManager->disposing();
83 void SAL_CALL OSingleDocumentController::disposing( const EventObject& i_event ) throw( RuntimeException, std::exception )
85 // simply disambiguate
86 OSingleDocumentController_Base::disposing( i_event );
89 void OSingleDocumentController::ClearUndoManager()
91 GetUndoManager().Clear();
94 SfxUndoManager& OSingleDocumentController::GetUndoManager() const
96 return m_pData->m_pUndoManager->GetSfxUndoManager();
99 void OSingleDocumentController::addUndoActionAndInvalidate(SfxUndoAction *_pAction)
101 // add undo action
102 GetUndoManager().AddUndoAction( _pAction );
104 // when we add an undo action the controller was modified
105 setModified( sal_True );
107 // now inform me that or states changed
108 InvalidateFeature( ID_BROWSER_UNDO );
109 InvalidateFeature( ID_BROWSER_REDO );
112 Reference< XUndoManager > SAL_CALL OSingleDocumentController::getUndoManager( ) throw (RuntimeException, std::exception)
114 return m_pData->m_pUndoManager.get();
117 FeatureState OSingleDocumentController::GetState(sal_uInt16 _nId) const
119 FeatureState aReturn;
120 switch ( _nId )
122 case ID_BROWSER_UNDO:
123 aReturn.bEnabled = isEditable() && GetUndoManager().GetUndoActionCount() != 0;
124 if ( aReturn.bEnabled )
126 OUString sUndo(ModuleRes(STR_UNDO_COLON));
127 sUndo += " ";
128 sUndo += GetUndoManager().GetUndoActionComment();
129 aReturn.sTitle = sUndo;
131 break;
133 case ID_BROWSER_REDO:
134 aReturn.bEnabled = isEditable() && GetUndoManager().GetRedoActionCount() != 0;
135 if ( aReturn.bEnabled )
137 OUString sRedo(ModuleRes(STR_REDO_COLON));
138 sRedo += " ";
139 sRedo += GetUndoManager().GetRedoActionComment();
140 aReturn.sTitle = sRedo;
142 break;
144 default:
145 aReturn = OSingleDocumentController_Base::GetState(_nId);
147 return aReturn;
149 void OSingleDocumentController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue >& _rArgs )
151 switch ( _nId )
153 case ID_BROWSER_UNDO:
154 GetUndoManager().Undo();
155 InvalidateFeature( ID_BROWSER_UNDO );
156 InvalidateFeature( ID_BROWSER_REDO );
157 break;
159 case ID_BROWSER_REDO:
160 GetUndoManager().Redo();
161 InvalidateFeature( ID_BROWSER_UNDO );
162 InvalidateFeature( ID_BROWSER_REDO );
163 break;
165 default:
166 OSingleDocumentController_Base::Execute( _nId, _rArgs );
167 break;
169 InvalidateFeature(_nId);
172 } // namespace dbaui
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */