sc: factor out some more code
[LibreOffice.git] / sw / source / ui / vba / vbarevision.cxx
blob6b5b4c1a7808e1fc5304afe3e028a07a5bd57616
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 .
19 #include "vbarevision.hxx"
20 #include <sal/log.hxx>
21 #include <com/sun/star/document/XRedlinesSupplier.hpp>
22 #include <com/sun/star/container/XIndexAccess.hpp>
23 #include <com/sun/star/frame/XModel.hpp>
24 #include "wordvbahelper.hxx"
25 #include <docsh.hxx>
26 #include <doc.hxx>
27 #include <IDocumentRedlineAccess.hxx>
28 #include <unotxdoc.hxx>
29 #include <unoredlines.hxx>
30 #include <utility>
32 using namespace ::ooo::vba;
33 using namespace ::com::sun::star;
35 SwVbaRevision::SwVbaRevision( const uno::Reference< ooo::vba::XHelperInterface >& rParent,
36 const uno::Reference< uno::XComponentContext >& rContext,
37 rtl::Reference< SwXTextDocument > xModel,
38 uno::Reference< beans::XPropertySet > xRedlineProps )
39 : SwVbaRevision_BASE( rParent, rContext ),
40 mxModel(std::move( xModel )),
41 mxRedlineProps(std::move( xRedlineProps ))
45 SwVbaRevision::~SwVbaRevision()
49 sal_Int32 SwVbaRevision::GetPosition()
51 sal_Int32 nPos = -1;
52 rtl::Reference< SwXRedlines > xRedlines( mxModel->getSwRedlines() );
53 sal_Int32 nCount = xRedlines->getCount();
54 for( sal_Int32 i = 0; i < nCount; i++ )
56 uno::Reference< beans::XPropertySet > xProps( xRedlines->getByIndex( i ), uno::UNO_QUERY_THROW );
57 if( xProps == mxRedlineProps )
59 nPos = i;
60 SAL_INFO("sw.ui", "the redline position is " << nPos);
61 break;
64 if( nPos == -1 )
65 throw uno::RuntimeException();
67 return nPos;
70 void SAL_CALL
71 SwVbaRevision::Accept()
73 SwDoc* pDoc = mxModel->GetDocShell()->GetDoc();
74 if( pDoc )
75 pDoc->getIDocumentRedlineAccess().AcceptRedline( GetPosition(), true );
78 void SAL_CALL
79 SwVbaRevision::Reject( )
81 SwDoc* pDoc = mxModel->GetDocShell()->GetDoc();
82 if( pDoc )
83 pDoc->getIDocumentRedlineAccess().RejectRedline( GetPosition(), true );
86 OUString
87 SwVbaRevision::getServiceImplName()
89 return u"SwVbaRevision"_ustr;
92 uno::Sequence< OUString >
93 SwVbaRevision::getServiceNames()
95 static uno::Sequence< OUString > const aServiceNames
97 u"ooo.vba.word.Revision"_ustr
99 return aServiceNames;
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */