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_SC_SOURCE_UI_VBA_EXCELVBAHELPER_HXX
20 #define INCLUDED_SC_SOURCE_UI_VBA_EXCELVBAHELPER_HXX
21 
22 #include <com/sun/star/lang/XUnoTunnel.hpp>
23 #include <vector>
24 #include <global.hxx>
25 
26 namespace com { namespace sun { namespace star { namespace frame { class XModel; } } } }
27 namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } }
28 
29 namespace com { namespace sun { namespace star { namespace sheet { class XDatabaseRange; } } } }
30 namespace com { namespace sun { namespace star { namespace sheet { class XUnnamedDatabaseRanges; } } } }
31 namespace com { namespace sun { namespace star { namespace table { class XCell; } } } }
32 namespace com { namespace sun { namespace star { namespace table { class XCellRange; } } } }
33 namespace com { namespace sun { namespace star { namespace sheet { class XSheetCellRangeContainer; } } } }
34 namespace com { namespace sun { namespace star { namespace sheet { class XSpreadsheet; } } } }
35 namespace com { namespace sun { namespace star { namespace sheet { class XSpreadsheetDocument; } } } }
36 namespace ooo { namespace vba { class XHelperInterface; } }
37 
38 class ScCellRangesBase;
39 class ScTabViewShell;
40 class SfxViewFrame;
41 
42 namespace ooo {
43 namespace vba {
44 namespace excel {
45 
46 // nTabs empty means apply zoom to all sheets
47 void implSetZoom( const css::uno::Reference< css::frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs );
48 void implnCopy( const css::uno::Reference< css::frame::XModel>& xModel );
49 void implnPaste ( const css::uno::Reference< css::frame::XModel>& xModel );
50 void implnCut( const css::uno::Reference< css::frame::XModel>& xModel );
51 void implnPasteSpecial( const css::uno::Reference< css::frame::XModel>& xModel, InsertDeleteFlags nFlags, ScPasteFunc nFunction, bool bSkipEmpty, bool bTranspose);
52 ScTabViewShell* getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel ) ;
53 ScDocShell* getDocShell( const css::uno::Reference< css::frame::XModel>& xModel ) ;
54 ScTabViewShell* getCurrentBestViewShell( const css::uno::Reference< css::uno::XComponentContext >& xContext );
55 SfxViewFrame* getViewFrame( const css::uno::Reference< css::frame::XModel >& xModel );
56 
57 /// @throws css::uno::RuntimeException
58 css::uno::Reference< css::sheet::XUnnamedDatabaseRanges > GetUnnamedDataBaseRanges( const ScDocShell* pShell );
59 
60 /// @throws css::uno::RuntimeException
61 css::uno::Reference< css::sheet::XDatabaseRange > GetAutoFiltRange( const ScDocShell* pShell, sal_Int16 nSheet );
62 /// @throws css::uno::RuntimeException
63 css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSpreadsheet >& xSheet );
64 /// @throws css::uno::RuntimeException
65 css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges );
66 /// @throws css::uno::RuntimeException
67 css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCellRange >& xRange );
68 /// @throws css::uno::RuntimeException
69 css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCell >& xCell );
70 /// @throws css::uno::RuntimeException
71 css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::frame::XModel >& xModel, SCTAB nTab );
72 
73 /// @throws css::uno::RuntimeException
74 ScDocShell* GetDocShellFromRange( const css::uno::Reference< css::uno::XInterface >& xRange );
75 void setUpDocumentModules( const css::uno::Reference< css::sheet::XSpreadsheetDocument >& xDoc );
76 
77 class ScVbaCellRangeAccess
78 {
79 public:
80     static SfxItemSet* GetDataSet( ScCellRangesBase* pRangeObj );
81 };
82 
83 // Extracts an implementation object (via XUnoTunnel) from a UNO object.
84 // Will throw if unsuccessful.
85 /// @throws css::uno::RuntimeException
86 template < typename ImplObject >
getImplFromDocModuleWrapper(const css::uno::Reference<css::uno::XInterface> & rxWrapperIf)87     ImplObject* getImplFromDocModuleWrapper( const css::uno::Reference< css::uno::XInterface >& rxWrapperIf )
88     {
89         ImplObject* pObj = nullptr;
90         css::uno::Reference< css::lang::XUnoTunnel >  xTunnel( rxWrapperIf, css::uno::UNO_QUERY );
91         if ( xTunnel.is() )
92             pObj = reinterpret_cast<ImplObject*>( xTunnel->getSomething(ImplObject::getUnoTunnelId()));
93         if ( !pObj )
94             throw css::uno::RuntimeException("Internal error, can't extract implementation object", rxWrapperIf );
95         return pObj;
96     }
97 
98 } // namespace excel
99 } // namespace vba
100 } // namespace ooo
101 
102 #endif
103 
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
105