1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbahelper.cxx,v $
10 * $Revision: 1.5.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "excelvbahelper.hxx"
32 #include "tabvwsh.hxx"
33 #include "transobj.hxx"
35 #include "cellsuno.hxx"
36 #include <comphelper/processfactory.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::ooo::vba
;
47 void implSetZoom( const uno::Reference
< frame::XModel
>& xModel
, sal_Int16 nZoom
, std::vector
< SCTAB
>& nTabs
)
49 ScTabViewShell
* pViewSh
= excel::getBestViewShell( xModel
);
50 Fraction
aFract( nZoom
, 100 );
51 pViewSh
->GetViewData()->SetZoom( aFract
, aFract
, nTabs
);
52 pViewSh
->RefreshZoom();
54 bool isInPrintPreview( SfxViewFrame
* pView
)
56 sal_uInt16 nViewNo
= SID_VIEWSHELL1
- SID_VIEWSHELL0
;
57 if ( pView
->GetObjectShell()->GetFactory().GetViewFactoryCount() >
58 nViewNo
&& !pView
->GetObjectShell()->IsInPlaceActive() )
60 SfxViewFactory
&rViewFactory
=
61 pView
->GetObjectShell()->GetFactory().GetViewFactory(nViewNo
);
62 if ( pView
->GetCurViewId() == rViewFactory
.GetOrdinal() )
68 const ::rtl::OUString
REPLACE_CELLS_WARNING( RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning"));
70 class PasteCellsWarningReseter
73 bool bInitialWarningState
;
74 static uno::Reference
< beans::XPropertySet
> getGlobalSheetSettings() throw ( uno::RuntimeException
)
76 static uno::Reference
< beans::XPropertySet
> xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW
);
77 static uno::Reference
<uno::XComponentContext
> xContext( xTmpProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW
);
78 static uno::Reference
<lang::XMultiComponentFactory
> xServiceManager(
79 xContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
80 static uno::Reference
< beans::XPropertySet
> xProps( xServiceManager
->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext
), uno::UNO_QUERY_THROW
);
84 bool getReplaceCellsWarning() throw ( uno::RuntimeException
)
86 sal_Bool res
= sal_False
;
87 getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING
) >>= res
;
88 return ( res
== sal_True
);
91 void setReplaceCellsWarning( bool bState
) throw ( uno::RuntimeException
)
93 getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING
, uno::makeAny( bState
) );
96 PasteCellsWarningReseter() throw ( uno::RuntimeException
)
98 bInitialWarningState
= getReplaceCellsWarning();
99 if ( bInitialWarningState
)
100 setReplaceCellsWarning( false );
102 ~PasteCellsWarningReseter()
104 if ( bInitialWarningState
)
106 // don't allow dtor to throw
109 setReplaceCellsWarning( true );
111 catch ( uno::Exception
& /*e*/ ){}
117 implnPaste( const uno::Reference
< frame::XModel
>& xModel
)
119 PasteCellsWarningReseter resetWarningBox
;
120 ScTabViewShell
* pViewShell
= getBestViewShell( xModel
);
123 pViewShell
->PasteFromSystem();
124 pViewShell
->CellContentChanged();
130 implnCopy( const uno::Reference
< frame::XModel
>& xModel
)
132 ScTabViewShell
* pViewShell
= getBestViewShell( xModel
);
134 pViewShell
->CopyToClip(NULL
,false,false,true);
138 implnCut( const uno::Reference
< frame::XModel
>& xModel
)
140 ScTabViewShell
* pViewShell
= getBestViewShell( xModel
);
142 pViewShell
->CutToClip( NULL
, TRUE
);
145 void implnPasteSpecial( const uno::Reference
< frame::XModel
>& xModel
, USHORT nFlags
,USHORT nFunction
,sal_Bool bSkipEmpty
, sal_Bool bTranspose
)
147 PasteCellsWarningReseter resetWarningBox
;
148 sal_Bool
bAsLink(sal_False
), bOtherDoc(sal_False
);
149 InsCellCmd eMoveMode
= INS_NONE
;
151 ScTabViewShell
* pTabViewShell
= getBestViewShell( xModel
);
154 ScViewData
* pView
= pTabViewShell
->GetViewData();
155 Window
* pWin
= ( pView
!= NULL
) ? pView
->GetActiveWin() : NULL
;
158 if ( bAsLink
&& bOtherDoc
)
159 pTabViewShell
->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK
162 ScTransferObj
* pOwnClip
= ScTransferObj::GetOwnClipboard( pWin
);
163 ScDocument
* pDoc
= NULL
;
165 pDoc
= pOwnClip
->GetDocument();
166 pTabViewShell
->PasteFromClip( nFlags
, pDoc
,
167 nFunction
, bSkipEmpty
, bTranspose
, bAsLink
,
168 eMoveMode
, IDF_NONE
, TRUE
);
169 pTabViewShell
->CellContentChanged();
177 getDocShell( const css::uno::Reference
< css::frame::XModel
>& xModel
)
179 uno::Reference
< uno::XInterface
> xIf( xModel
, uno::UNO_QUERY_THROW
);
180 ScModelObj
* pModel
= dynamic_cast< ScModelObj
* >( xIf
.get() );
181 ScDocShell
* pDocShell
= NULL
;
183 pDocShell
= (ScDocShell
*)pModel
->GetEmbeddedObject();
189 getBestViewShell( const css::uno::Reference
< css::frame::XModel
>& xModel
)
191 ScDocShell
* pDocShell
= getDocShell( xModel
);
193 return pDocShell
->GetBestViewShell();
198 getCurrentBestViewShell( const uno::Reference
< uno::XComponentContext
>& xContext
)
200 uno::Reference
< frame::XModel
> xModel
= getCurrentExcelDoc( xContext
);
201 return getBestViewShell( xModel
);
205 getViewFrame( const uno::Reference
< frame::XModel
>& xModel
)
207 ScTabViewShell
* pViewShell
= getBestViewShell( xModel
);
209 return pViewShell
->GetViewFrame();
214 ScVbaCellRangeAccess::GetDataSet( ScCellRangeObj
* pRangeObj
)
216 SfxItemSet
* pDataSet
= pRangeObj
? pRangeObj
->GetCurrentDataSet( true ) : NULL
;