1*e6ed5fbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e6ed5fbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e6ed5fbcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e6ed5fbcSAndrew Rist * distributed with this work for additional information
6*e6ed5fbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e6ed5fbcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e6ed5fbcSAndrew Rist * "License"); you may not use this file except in compliance
9*e6ed5fbcSAndrew Rist * with the License. You may obtain a copy of the License at
10*e6ed5fbcSAndrew Rist *
11*e6ed5fbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e6ed5fbcSAndrew Rist *
13*e6ed5fbcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e6ed5fbcSAndrew Rist * software distributed under the License is distributed on an
15*e6ed5fbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e6ed5fbcSAndrew Rist * KIND, either express or implied. See the License for the
17*e6ed5fbcSAndrew Rist * specific language governing permissions and limitations
18*e6ed5fbcSAndrew Rist * under the License.
19*e6ed5fbcSAndrew Rist *
20*e6ed5fbcSAndrew Rist *************************************************************/
21*e6ed5fbcSAndrew Rist
22*e6ed5fbcSAndrew Rist
23cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
24cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
25cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
26cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
27cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
28cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
29cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
30cdf0e10cSrcweir #include <com/sun/star/frame/XModel2.hpp>
31cdf0e10cSrcweir #include <com/sun/star/script/XDefaultProperty.hpp>
32cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
35cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/XIntrospection.hpp>
37cdf0e10cSrcweir #include <com/sun/star/util/MeasureUnit.hpp>
38cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
39cdf0e10cSrcweir #include <com/sun/star/awt/XDialog.hpp>
40cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <ooo/vba/msforms/XShape.hpp>
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <sfx2/objsh.hxx>
47cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
48cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
49cdf0e10cSrcweir #include <sfx2/app.hxx>
50cdf0e10cSrcweir #include <svl/stritem.hxx>
51cdf0e10cSrcweir #include <svl/eitem.hxx>
52cdf0e10cSrcweir #include <svl/intitem.hxx>
53cdf0e10cSrcweir #include <svl/itemset.hxx>
54cdf0e10cSrcweir #include <sfx2/docfac.hxx>
55cdf0e10cSrcweir #include <sfx2/viewfac.hxx>
56cdf0e10cSrcweir
57cdf0e10cSrcweir #include <basic/sbx.hxx>
58cdf0e10cSrcweir #include <basic/sbstar.hxx>
59cdf0e10cSrcweir #include <basic/basmgr.hxx>
60cdf0e10cSrcweir #include <basic/sbmod.hxx>
61cdf0e10cSrcweir #include <basic/sbmeth.hxx>
62cdf0e10cSrcweir #include <rtl/math.hxx>
63cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
64cdf0e10cSrcweir #include <math.h>
65cdf0e10cSrcweir #include <tools/urlobj.hxx>
66cdf0e10cSrcweir #include <osl/file.hxx>
67cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
68cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
69cdf0e10cSrcweir #include <vcl/window.hxx>
70cdf0e10cSrcweir #include <vcl/syswin.hxx>
71cdf0e10cSrcweir #include <tools/diagnose_ex.h>
72cdf0e10cSrcweir
73cdf0e10cSrcweir #ifndef OOVBA_DLLIMPLEMENTATION
74cdf0e10cSrcweir #define OOVBA_DLLIMPLEMENTATION
75cdf0e10cSrcweir #endif
76cdf0e10cSrcweir
77cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
78cdf0e10cSrcweir #include <sfx2/app.hxx>
79cdf0e10cSrcweir // #FIXME needs service
80cdf0e10cSrcweir //#include "vbashape.hxx"
81cdf0e10cSrcweir //#include "unonames.hxx"
82cdf0e10cSrcweir
83cdf0e10cSrcweir using namespace ::com::sun::star;
84cdf0e10cSrcweir using namespace ::ooo::vba;
85cdf0e10cSrcweir
86cdf0e10cSrcweir void unoToSbxValue( SbxVariable* pVar, const uno::Any& aValue );
87cdf0e10cSrcweir
88cdf0e10cSrcweir uno::Any sbxToUnoValue( SbxVariable* pVar );
89cdf0e10cSrcweir
90cdf0e10cSrcweir
91cdf0e10cSrcweir namespace ooo
92cdf0e10cSrcweir {
93cdf0e10cSrcweir namespace vba
94cdf0e10cSrcweir {
95cdf0e10cSrcweir
96cdf0e10cSrcweir namespace { const double factor = 2540.0 / 72.0; }
97cdf0e10cSrcweir
createVBAUnoAPIService(SfxObjectShell * pShell,const sal_Char * _pAsciiName)98cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" );
101cdf0e10cSrcweir ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) );
102cdf0e10cSrcweir return getVBAServiceFactory( pShell )->createInstance( sVarName );
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir // helper method to determine if the view ( calc ) is in print-preview mode
isInPrintPreview(SfxViewFrame * pView)106cdf0e10cSrcweir bool isInPrintPreview( SfxViewFrame* pView )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0;
109cdf0e10cSrcweir if ( pView->GetObjectShell()->GetFactory().GetViewFactoryCount() >
110cdf0e10cSrcweir nViewNo && !pView->GetObjectShell()->IsInPlaceActive() )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir SfxViewFactory &rViewFactory =
113cdf0e10cSrcweir pView->GetObjectShell()->GetFactory().GetViewFactory(nViewNo);
114cdf0e10cSrcweir if ( pView->GetCurViewId() == rViewFactory.GetOrdinal() )
115cdf0e10cSrcweir return true;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir return false;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir #if 0
120cdf0e10cSrcweir namespace excel // all in this namespace probably can be moved to sc
121cdf0e10cSrcweir {
122cdf0e10cSrcweir
123cdf0e10cSrcweir
124cdf0e10cSrcweir const ::rtl::OUString REPLACE_CELLS_WARNING( RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning"));
125cdf0e10cSrcweir class PasteCellsWarningReseter
126cdf0e10cSrcweir {
127cdf0e10cSrcweir private:
128cdf0e10cSrcweir bool bInitialWarningState;
129cdf0e10cSrcweir static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
132cdf0e10cSrcweir static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
133cdf0e10cSrcweir static uno::Reference<lang::XMultiComponentFactory > xServiceManager(
134cdf0e10cSrcweir xContext->getServiceManager(), uno::UNO_QUERY_THROW );
135cdf0e10cSrcweir static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW );
136cdf0e10cSrcweir return xProps;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir bool getReplaceCellsWarning() throw ( uno::RuntimeException )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir sal_Bool res = sal_False;
142cdf0e10cSrcweir getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING ) >>= res;
143cdf0e10cSrcweir return ( res == sal_True );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir void setReplaceCellsWarning( bool bState ) throw ( uno::RuntimeException )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING, uno::makeAny( bState ) );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir public:
151cdf0e10cSrcweir PasteCellsWarningReseter() throw ( uno::RuntimeException )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir bInitialWarningState = getReplaceCellsWarning();
154cdf0e10cSrcweir if ( bInitialWarningState )
155cdf0e10cSrcweir setReplaceCellsWarning( false );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir ~PasteCellsWarningReseter()
158cdf0e10cSrcweir {
159cdf0e10cSrcweir if ( bInitialWarningState )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir // don't allow dtor to throw
162cdf0e10cSrcweir try
163cdf0e10cSrcweir {
164cdf0e10cSrcweir setReplaceCellsWarning( true );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir catch ( uno::Exception& /*e*/ ){}
167cdf0e10cSrcweir }
168cdf0e10cSrcweir }
169cdf0e10cSrcweir };
170cdf0e10cSrcweir
171cdf0e10cSrcweir void
172cdf0e10cSrcweir implnPaste()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir PasteCellsWarningReseter resetWarningBox;
175cdf0e10cSrcweir ScTabViewShell* pViewShell = getCurrentBestViewShell();
176cdf0e10cSrcweir if ( pViewShell )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir pViewShell->PasteFromSystem();
179cdf0e10cSrcweir pViewShell->CellContentChanged();
180cdf0e10cSrcweir }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
183cdf0e10cSrcweir
184cdf0e10cSrcweir void
185cdf0e10cSrcweir implnCopy()
186cdf0e10cSrcweir {
187cdf0e10cSrcweir ScTabViewShell* pViewShell = getCurrentBestViewShell();
188cdf0e10cSrcweir if ( pViewShell )
189cdf0e10cSrcweir pViewShell->CopyToClip(NULL,false,false,true);
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir void
193cdf0e10cSrcweir implnCut()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir ScTabViewShell* pViewShell = getCurrentBestViewShell();
196cdf0e10cSrcweir if ( pViewShell )
197cdf0e10cSrcweir pViewShell->CutToClip( NULL, sal_True );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir void implnPasteSpecial(SfxViewShell* pViewShell, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir PasteCellsWarningReseter resetWarningBox;
202cdf0e10cSrcweir sal_Bool bAsLink(sal_False), bOtherDoc(sal_False);
203cdf0e10cSrcweir InsCellCmd eMoveMode = INS_NONE;
204cdf0e10cSrcweir
205cdf0e10cSrcweir if ( !pTabViewShell )
206cdf0e10cSrcweir // none active, try next best
207cdf0e10cSrcweir pTabViewShell = getCurrentBestViewShell();
208cdf0e10cSrcweir if ( pTabViewShell )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir ScViewData* pView = pTabViewShell->GetViewData();
211cdf0e10cSrcweir Window* pWin = ( pView != NULL ) ? pView->GetActiveWin() : NULL;
212cdf0e10cSrcweir if ( pView && pWin )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir if ( bAsLink && bOtherDoc )
215cdf0e10cSrcweir pTabViewShell->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK
216cdf0e10cSrcweir else
217cdf0e10cSrcweir {
218cdf0e10cSrcweir ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin );
219cdf0e10cSrcweir ScDocument* pDoc = NULL;
220cdf0e10cSrcweir if ( pOwnClip )
221cdf0e10cSrcweir pDoc = pOwnClip->GetDocument();
222cdf0e10cSrcweir pTabViewShell->PasteFromClip( nFlags, pDoc,
223cdf0e10cSrcweir nFunction, bSkipEmpty, bTranspose, bAsLink,
224cdf0e10cSrcweir eMoveMode, IDF_NONE, sal_True );
225cdf0e10cSrcweir pTabViewShell->CellContentChanged();
226cdf0e10cSrcweir }
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir ScDocShell*
233cdf0e10cSrcweir getDocShell( css::uno::Reference< css::frame::XModel>& xModel )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW );
236cdf0e10cSrcweir ScModelObj* pModel = dynamic_cast< ScModelObj* >( xIf.get() );
237cdf0e10cSrcweir ScDocShell* pDocShell = NULL;
238cdf0e10cSrcweir if ( pModel )
239cdf0e10cSrcweir pDocShell = (ScDocShell*)pModel->GetEmbeddedObject();
240cdf0e10cSrcweir return pDocShell;
241cdf0e10cSrcweir
242cdf0e10cSrcweir }
243cdf0e10cSrcweir
244cdf0e10cSrcweir ScTabViewShell*
245cdf0e10cSrcweir getBestViewShell( css::uno::Reference< css::frame::XModel>& xModel )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir ScDocShell* pDocShell = getDocShell( xModel );
248cdf0e10cSrcweir if ( pDocShell )
249cdf0e10cSrcweir return pDocShell->GetBestViewShell();
250cdf0e10cSrcweir return NULL;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
253cdf0e10cSrcweir ScTabViewShell*
254cdf0e10cSrcweir getCurrentBestViewShell()
255cdf0e10cSrcweir {
256cdf0e10cSrcweir uno::Reference< frame::XModel > xModel = getCurrentDocument();
257cdf0e10cSrcweir return getBestViewShell( xModel );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir SfxViewFrame*
261cdf0e10cSrcweir getCurrentViewFrame()
262cdf0e10cSrcweir {
263cdf0e10cSrcweir ScTabViewShell* pViewShell = getCurrentBestViewShell();
264cdf0e10cSrcweir if ( pViewShell )
265cdf0e10cSrcweir return pViewShell->GetViewFrame();
266cdf0e10cSrcweir return NULL;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir };
269cdf0e10cSrcweir
270cdf0e10cSrcweir #endif
271cdf0e10cSrcweir
272cdf0e10cSrcweir uno::Reference< beans::XIntrospectionAccess >
getIntrospectionAccess(const uno::Any & aObject)273cdf0e10cSrcweir getIntrospectionAccess( const uno::Any& aObject ) throw (uno::RuntimeException)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir static uno::Reference< beans::XIntrospection > xIntrospection;
276cdf0e10cSrcweir if( !xIntrospection.is() )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
279cdf0e10cSrcweir xIntrospection.set( xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection") ), uno::UNO_QUERY_THROW );
280cdf0e10cSrcweir }
281cdf0e10cSrcweir return xIntrospection->inspect( aObject );
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir uno::Reference< script::XTypeConverter >
getTypeConverter(const uno::Reference<uno::XComponentContext> & xContext)285cdf0e10cSrcweir getTypeConverter( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir static uno::Reference< script::XTypeConverter > xTypeConv( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter") ), xContext ), uno::UNO_QUERY_THROW );
288cdf0e10cSrcweir return xTypeConv;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir const uno::Any&
aNULL()291cdf0e10cSrcweir aNULL()
292cdf0e10cSrcweir {
293cdf0e10cSrcweir static uno::Any aNULLL = uno::makeAny( uno::Reference< uno::XInterface >() );
294cdf0e10cSrcweir return aNULLL;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
dispatchExecute(SfxViewShell * pViewShell,sal_uInt16 nSlot,SfxCallMode nCall)297cdf0e10cSrcweir void dispatchExecute(SfxViewShell* pViewShell, sal_uInt16 nSlot, SfxCallMode nCall)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir SfxViewFrame* pViewFrame = NULL;
300cdf0e10cSrcweir if ( pViewShell )
301cdf0e10cSrcweir pViewFrame = pViewShell->GetViewFrame();
302cdf0e10cSrcweir if ( pViewFrame )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
305cdf0e10cSrcweir if( pDispatcher )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir pDispatcher->Execute( nSlot , nCall );
308cdf0e10cSrcweir }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
312cdf0e10cSrcweir void
dispatchRequests(const uno::Reference<frame::XModel> & xModel,const rtl::OUString & aUrl,const uno::Sequence<beans::PropertyValue> & sProps)313cdf0e10cSrcweir dispatchRequests( const uno::Reference< frame::XModel>& xModel, const rtl::OUString& aUrl, const uno::Sequence< beans::PropertyValue >& sProps )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir util::URL url;
316cdf0e10cSrcweir url.Complete = aUrl;
317cdf0e10cSrcweir rtl::OUString emptyString = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ));
318cdf0e10cSrcweir uno::Reference<frame::XController> xController = xModel->getCurrentController();
319cdf0e10cSrcweir uno::Reference<frame::XFrame> xFrame = xController->getFrame();
320cdf0e10cSrcweir uno::Reference<frame::XDispatchProvider> xDispatchProvider (xFrame,uno::UNO_QUERY_THROW);
321cdf0e10cSrcweir try
322cdf0e10cSrcweir {
323cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
324cdf0e10cSrcweir uno::Reference<uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
325cdf0e10cSrcweir if ( !xContext.is() )
326cdf0e10cSrcweir return;
327cdf0e10cSrcweir
328cdf0e10cSrcweir uno::Reference<lang::XMultiComponentFactory > xServiceManager = xContext->getServiceManager();
329cdf0e10cSrcweir if ( !xServiceManager.is() )
330cdf0e10cSrcweir return;
331cdf0e10cSrcweir
332cdf0e10cSrcweir uno::Reference<util::XURLTransformer> xParser( xServiceManager->createInstanceWithContext(
333cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) ), xContext),
334cdf0e10cSrcweir uno::UNO_QUERY_THROW );
335cdf0e10cSrcweir if (!xParser.is())
336cdf0e10cSrcweir return;
337cdf0e10cSrcweir xParser->parseStrict (url);
338cdf0e10cSrcweir }
339cdf0e10cSrcweir catch ( uno::Exception & /*e*/ )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir return;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
344cdf0e10cSrcweir uno::Reference<frame::XDispatch> xDispatcher = xDispatchProvider->queryDispatch(url,emptyString,0);
345cdf0e10cSrcweir
346cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> dispatchProps(1);
347cdf0e10cSrcweir
348cdf0e10cSrcweir sal_Int32 nProps = sProps.getLength();
349cdf0e10cSrcweir beans::PropertyValue* pDest = dispatchProps.getArray();
350cdf0e10cSrcweir if ( nProps )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir dispatchProps.realloc( nProps + 1 );
353cdf0e10cSrcweir // need to reaccquire pDest after realloc
354cdf0e10cSrcweir pDest = dispatchProps.getArray();
355cdf0e10cSrcweir const beans::PropertyValue* pSrc = sProps.getConstArray();
356cdf0e10cSrcweir for ( sal_Int32 index=0; index<nProps; ++index, ++pSrc, ++pDest )
357cdf0e10cSrcweir *pDest = *pSrc;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir (*pDest).Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Silent" ));
361cdf0e10cSrcweir (*pDest).Value <<= (sal_Bool)sal_True;
362cdf0e10cSrcweir
363cdf0e10cSrcweir if (xDispatcher.is())
364cdf0e10cSrcweir xDispatcher->dispatch( url, dispatchProps );
365cdf0e10cSrcweir }
366cdf0e10cSrcweir
367cdf0e10cSrcweir void
dispatchRequests(const uno::Reference<frame::XModel> & xModel,const rtl::OUString & aUrl)368cdf0e10cSrcweir dispatchRequests( const uno::Reference< frame::XModel>& xModel, const rtl::OUString& aUrl )
369cdf0e10cSrcweir {
370cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> dispatchProps;
371cdf0e10cSrcweir dispatchRequests( xModel, aUrl, dispatchProps );
372cdf0e10cSrcweir }
373cdf0e10cSrcweir
374cdf0e10cSrcweir uno::Reference< frame::XModel >
getCurrentDoc(const rtl::OUString & sKey)375cdf0e10cSrcweir getCurrentDoc( const rtl::OUString& sKey ) throw (uno::RuntimeException)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir uno::Reference< frame::XModel > xModel;
378cdf0e10cSrcweir SbxObject* pBasic = dynamic_cast< SbxObject* > ( SFX_APP()->GetBasic() );
379cdf0e10cSrcweir SbxObject* basicChosen = pBasic ;
380cdf0e10cSrcweir if ( basicChosen == NULL)
381cdf0e10cSrcweir {
382cdf0e10cSrcweir OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" );
383cdf0e10cSrcweir return xModel;
384cdf0e10cSrcweir }
385cdf0e10cSrcweir SbxObject* p = pBasic;
386cdf0e10cSrcweir SbxObject* pParent = p->GetParent();
387cdf0e10cSrcweir SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL;
388cdf0e10cSrcweir
389cdf0e10cSrcweir if( pParentParent )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir basicChosen = pParentParent;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir else if( pParent )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir basicChosen = pParent;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir
398cdf0e10cSrcweir
399cdf0e10cSrcweir uno::Any aModel;
400cdf0e10cSrcweir SbxVariable *pCompVar = basicChosen->Find( sKey, SbxCLASS_OBJECT );
401cdf0e10cSrcweir
402cdf0e10cSrcweir if ( pCompVar )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir aModel = sbxToUnoValue( pCompVar );
405cdf0e10cSrcweir if ( sal_False == ( aModel >>= xModel ) ||
406cdf0e10cSrcweir !xModel.is() )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir throw uno::RuntimeException(
409cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract model from basic ( its obviously not set yet ) therefore don't know the current documet context") ), uno::Reference< uno::XInterface >() );
410cdf0e10cSrcweir }
411cdf0e10cSrcweir else
412cdf0e10cSrcweir {
413cdf0e10cSrcweir OSL_TRACE("Have model points to url %s",
414cdf0e10cSrcweir ::rtl::OUStringToOString( xModel->getURL(),
415cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
416cdf0e10cSrcweir }
417cdf0e10cSrcweir }
418cdf0e10cSrcweir else
419cdf0e10cSrcweir {
420cdf0e10cSrcweir OSL_TRACE("Failed to get %s", rtl::OUStringToOString( sKey, RTL_TEXTENCODING_UTF8 ).getStr() );
421cdf0e10cSrcweir throw uno::RuntimeException(
422cdf0e10cSrcweir rtl::OUString(
423cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
424cdf0e10cSrcweir "Can't determine the currently selected document") ),
425cdf0e10cSrcweir uno::Reference< uno::XInterface >() );
426cdf0e10cSrcweir }
427cdf0e10cSrcweir return xModel;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir
430cdf0e10cSrcweir uno::Reference< frame::XModel >
getCurrentDocCtx(const rtl::OUString & ctxName,const uno::Reference<uno::XComponentContext> & xContext)431cdf0e10cSrcweir getCurrentDocCtx( const rtl::OUString& ctxName, const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
432cdf0e10cSrcweir {
433cdf0e10cSrcweir uno::Reference< frame::XModel > xModel;
434cdf0e10cSrcweir // try fallback to calling doc
435cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xNameAccess( xContext, css::uno::UNO_QUERY_THROW );
436cdf0e10cSrcweir xModel.set( xNameAccess->getByName( ctxName ), uno::UNO_QUERY_THROW );
437cdf0e10cSrcweir return xModel;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir
440cdf0e10cSrcweir uno::Reference< frame::XModel >
getThisExcelDoc(const uno::Reference<uno::XComponentContext> & xContext)441cdf0e10cSrcweir getThisExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir return getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext" ) ), xContext );
444cdf0e10cSrcweir }
445cdf0e10cSrcweir
446cdf0e10cSrcweir uno::Reference< frame::XModel >
getThisWordDoc(const uno::Reference<uno::XComponentContext> & xContext)447cdf0e10cSrcweir getThisWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
448cdf0e10cSrcweir {
449cdf0e10cSrcweir return getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext" ) ), xContext );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir
452cdf0e10cSrcweir uno::Reference< frame::XModel >
getCurrentExcelDoc(const uno::Reference<uno::XComponentContext> & xContext)453cdf0e10cSrcweir getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
454cdf0e10cSrcweir {
455cdf0e10cSrcweir static const rtl::OUString sThisExcelDoc( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc" ) );
456cdf0e10cSrcweir uno::Reference< frame::XModel > xModel;
457cdf0e10cSrcweir try
458cdf0e10cSrcweir {
459cdf0e10cSrcweir xModel = getCurrentDoc( sThisExcelDoc );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir catch( uno::Exception& e )
462cdf0e10cSrcweir {
463cdf0e10cSrcweir xModel = getThisExcelDoc( xContext );
464cdf0e10cSrcweir }
465cdf0e10cSrcweir return xModel;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
468cdf0e10cSrcweir uno::Reference< frame::XModel >
getCurrentWordDoc(const uno::Reference<uno::XComponentContext> & xContext)469cdf0e10cSrcweir getCurrentWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException)
470cdf0e10cSrcweir {
471cdf0e10cSrcweir static const rtl::OUString sThisWordDoc( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc" ) );
472cdf0e10cSrcweir uno::Reference< frame::XModel > xModel;
473cdf0e10cSrcweir try
474cdf0e10cSrcweir {
475cdf0e10cSrcweir xModel = getCurrentDoc( sThisWordDoc );
476cdf0e10cSrcweir }
477cdf0e10cSrcweir catch( uno::Exception& e )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir xModel = getThisWordDoc( xContext );
480cdf0e10cSrcweir }
481cdf0e10cSrcweir return xModel;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir
484cdf0e10cSrcweir sal_Int32
OORGBToXLRGB(sal_Int32 nCol)485cdf0e10cSrcweir OORGBToXLRGB( sal_Int32 nCol )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir sal_Int32 nAutoBits = nCol;
488cdf0e10cSrcweir nAutoBits &= 0xFF000000;
489cdf0e10cSrcweir sal_Int32 nRed = nCol;
490cdf0e10cSrcweir nRed &= 0x00FF0000;
491cdf0e10cSrcweir nRed >>= 16;
492cdf0e10cSrcweir sal_Int32 nGreen = nCol;
493cdf0e10cSrcweir nGreen &= 0x0000FF00;
494cdf0e10cSrcweir nGreen >>= 8;
495cdf0e10cSrcweir sal_Int32 nBlue = nCol;
496cdf0e10cSrcweir nBlue &= 0x000000FF;
497cdf0e10cSrcweir sal_Int32 nRGB = ( nAutoBits | (nBlue << 16) | (nGreen << 8) | nRed );
498cdf0e10cSrcweir return nRGB;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir sal_Int32
XLRGBToOORGB(sal_Int32 nCol)501cdf0e10cSrcweir XLRGBToOORGB( sal_Int32 nCol )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir sal_Int32 nAutoBits = nCol;
504cdf0e10cSrcweir nAutoBits &= 0xFF000000;
505cdf0e10cSrcweir
506cdf0e10cSrcweir sal_Int32 nBlue = nCol;
507cdf0e10cSrcweir nBlue &= 0x00FF0000;
508cdf0e10cSrcweir nBlue >>= 16;
509cdf0e10cSrcweir sal_Int32 nGreen = nCol;
510cdf0e10cSrcweir nGreen &= 0x0000FF00;
511cdf0e10cSrcweir nGreen >>= 8;
512cdf0e10cSrcweir sal_Int32 nRed = nCol;
513cdf0e10cSrcweir nRed &= 0x000000FF;
514cdf0e10cSrcweir sal_Int32 nRGB = ( nAutoBits | (nRed << 16) | (nGreen << 8) | nBlue );
515cdf0e10cSrcweir return nRGB;
516cdf0e10cSrcweir }
517cdf0e10cSrcweir uno::Any
OORGBToXLRGB(const uno::Any & aCol)518cdf0e10cSrcweir OORGBToXLRGB( const uno::Any& aCol )
519cdf0e10cSrcweir {
520cdf0e10cSrcweir sal_Int32 nCol(0);
521cdf0e10cSrcweir aCol >>= nCol;
522cdf0e10cSrcweir nCol = OORGBToXLRGB( nCol );
523cdf0e10cSrcweir return uno::makeAny( nCol );
524cdf0e10cSrcweir }
525cdf0e10cSrcweir uno::Any
XLRGBToOORGB(const uno::Any & aCol)526cdf0e10cSrcweir XLRGBToOORGB( const uno::Any& aCol )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir sal_Int32 nCol(0);
529cdf0e10cSrcweir aCol >>= nCol;
530cdf0e10cSrcweir nCol = XLRGBToOORGB( nCol );
531cdf0e10cSrcweir return uno::makeAny( nCol );
532cdf0e10cSrcweir }
533cdf0e10cSrcweir
PrintOutHelper(SfxViewShell * pViewShell,const uno::Any & From,const uno::Any & To,const uno::Any & Copies,const uno::Any & Preview,const uno::Any &,const uno::Any &,const uno::Any & Collate,const uno::Any & PrToFileName,sal_Bool bUseSelection)534cdf0e10cSrcweir void PrintOutHelper( SfxViewShell* pViewShell, const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& /*ActivePrinter*/, const uno::Any& /*PrintToFile*/, const uno::Any& Collate, const uno::Any& PrToFileName, sal_Bool bUseSelection )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir sal_Int32 nTo = 0;
537cdf0e10cSrcweir sal_Int32 nFrom = 0;
538cdf0e10cSrcweir sal_Int16 nCopies = 1;
539cdf0e10cSrcweir sal_Bool bPreview = sal_False;
540cdf0e10cSrcweir sal_Bool bCollate = sal_False;
541cdf0e10cSrcweir sal_Bool bSelection = bUseSelection;
542cdf0e10cSrcweir From >>= nFrom;
543cdf0e10cSrcweir To >>= nTo;
544cdf0e10cSrcweir Copies >>= nCopies;
545cdf0e10cSrcweir Preview >>= bPreview;
546cdf0e10cSrcweir if ( nCopies > 1 ) // Collate only useful when more that 1 copy
547cdf0e10cSrcweir Collate >>= bCollate;
548cdf0e10cSrcweir
549cdf0e10cSrcweir rtl::OUString sRange( RTL_CONSTASCII_USTRINGPARAM( "-" ) );
550cdf0e10cSrcweir rtl::OUString sFileName;
551cdf0e10cSrcweir
552cdf0e10cSrcweir if (( nFrom || nTo ) )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir if ( nFrom )
555cdf0e10cSrcweir sRange = ( ::rtl::OUString::valueOf( nFrom ) + sRange );
556cdf0e10cSrcweir if ( nTo )
557cdf0e10cSrcweir sRange += ::rtl::OUString::valueOf( nTo );
558cdf0e10cSrcweir }
559cdf0e10cSrcweir
560cdf0e10cSrcweir if ( PrToFileName.getValue() )
561cdf0e10cSrcweir {
562cdf0e10cSrcweir PrToFileName >>= sFileName;
563cdf0e10cSrcweir }
564cdf0e10cSrcweir SfxViewFrame* pViewFrame = NULL;
565cdf0e10cSrcweir if ( pViewShell )
566cdf0e10cSrcweir pViewFrame = pViewShell->GetViewFrame();
567cdf0e10cSrcweir if ( pViewFrame )
568cdf0e10cSrcweir {
569cdf0e10cSrcweir SfxAllItemSet aArgs( SFX_APP()->GetPool() );
570cdf0e10cSrcweir
571cdf0e10cSrcweir SfxBoolItem sfxCollate( SID_PRINT_COLLATE, bCollate );
572cdf0e10cSrcweir aArgs.Put( sfxCollate, sfxCollate.Which() );
573cdf0e10cSrcweir SfxInt16Item sfxCopies( SID_PRINT_COPIES, nCopies );
574cdf0e10cSrcweir aArgs.Put( sfxCopies, sfxCopies.Which() );
575cdf0e10cSrcweir if ( sFileName.getLength() )
576cdf0e10cSrcweir {
577cdf0e10cSrcweir SfxStringItem sfxFileName( SID_FILE_NAME, sFileName);
578cdf0e10cSrcweir aArgs.Put( sfxFileName, sfxFileName.Which() );
579cdf0e10cSrcweir
580cdf0e10cSrcweir }
581cdf0e10cSrcweir if ( sRange.getLength() )
582cdf0e10cSrcweir {
583cdf0e10cSrcweir SfxStringItem sfxRange( SID_PRINT_PAGES, sRange );
584cdf0e10cSrcweir aArgs.Put( sfxRange, sfxRange.Which() );
585cdf0e10cSrcweir }
586cdf0e10cSrcweir SfxBoolItem sfxSelection( SID_SELECTION, bSelection );
587cdf0e10cSrcweir aArgs.Put( sfxSelection, sfxSelection.Which() );
588cdf0e10cSrcweir SfxBoolItem sfxAsync( SID_ASYNCHRON, sal_False );
589cdf0e10cSrcweir aArgs.Put( sfxAsync, sfxAsync.Which() );
590cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
591cdf0e10cSrcweir
592cdf0e10cSrcweir if ( pDispatcher )
593cdf0e10cSrcweir {
594cdf0e10cSrcweir if ( bPreview )
595cdf0e10cSrcweir {
596cdf0e10cSrcweir if ( !pViewFrame->GetFrame().IsInPlace() )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir // #TODO is this necessary ( calc specific )
599cdf0e10cSrcweir // SC_MOD()->InputEnterHandler();
600cdf0e10cSrcweir pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_SYNCHRON );
601cdf0e10cSrcweir while ( isInPrintPreview( pViewFrame ) )
602cdf0e10cSrcweir Application::Yield();
603cdf0e10cSrcweir }
604cdf0e10cSrcweir }
605cdf0e10cSrcweir else
606cdf0e10cSrcweir pDispatcher->Execute( (sal_uInt16)SID_PRINTDOC, (SfxCallMode)SFX_CALLMODE_SYNCHRON, aArgs );
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
609cdf0e10cSrcweir }
610cdf0e10cSrcweir
611cdf0e10cSrcweir // #FIXME #TODO
612cdf0e10cSrcweir // 1 ActivePrinter ( how/can we switch a printer via API? )
613cdf0e10cSrcweir // 2 PrintToFile ( ms behaviour if this option is specified but no
614cdf0e10cSrcweir // filename supplied 'PrToFileName' then the user will be prompted )
615cdf0e10cSrcweir // 3 Need to check behaviour of Selected sheets with range ( e.g. From & To
616cdf0e10cSrcweir // values ) in oOO these options are mutually exclusive
617cdf0e10cSrcweir // 4 There is a pop up to do with transparent objects in the print source
618cdf0e10cSrcweir // should be able to disable that via configuration for the duration
619cdf0e10cSrcweir // of this method
620cdf0e10cSrcweir }
621cdf0e10cSrcweir
PrintPreviewHelper(const css::uno::Any &,SfxViewShell * pViewShell)622cdf0e10cSrcweir void PrintPreviewHelper( const css::uno::Any& /*EnableChanges*/, SfxViewShell* pViewShell )
623cdf0e10cSrcweir {
624cdf0e10cSrcweir dispatchExecute( pViewShell, SID_VIEWSHELL1 );
625cdf0e10cSrcweir }
626cdf0e10cSrcweir
extractIntFromAny(const uno::Any & rAny)627cdf0e10cSrcweir sal_Int32 extractIntFromAny( const uno::Any& rAny ) throw (uno::RuntimeException)
628cdf0e10cSrcweir {
629cdf0e10cSrcweir switch( rAny.getValueType().getTypeClass() )
630cdf0e10cSrcweir {
631cdf0e10cSrcweir case uno::TypeClass_FLOAT:
632cdf0e10cSrcweir return static_cast< sal_Int32 >( rAny.get< float >() );
633cdf0e10cSrcweir case uno::TypeClass_DOUBLE:
634cdf0e10cSrcweir return static_cast< sal_Int32 >( rAny.get< double >() );
635cdf0e10cSrcweir case uno::TypeClass_BYTE:
636cdf0e10cSrcweir case uno::TypeClass_SHORT:
637cdf0e10cSrcweir case uno::TypeClass_LONG:
638cdf0e10cSrcweir return rAny.get< sal_Int32 >();
639cdf0e10cSrcweir default:;
640cdf0e10cSrcweir }
641cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to integer." ) ), 0 );
642cdf0e10cSrcweir }
643cdf0e10cSrcweir
extractIntFromAny(const uno::Any & rAny,sal_Int32 nDefault)644cdf0e10cSrcweir sal_Int32 extractIntFromAny( const uno::Any& rAny, sal_Int32 nDefault ) throw (uno::RuntimeException)
645cdf0e10cSrcweir {
646cdf0e10cSrcweir return rAny.hasValue() ? extractIntFromAny( rAny ) : nDefault;
647cdf0e10cSrcweir }
648cdf0e10cSrcweir
extractBoolFromAny(const uno::Any & rAny)649cdf0e10cSrcweir bool extractBoolFromAny( const uno::Any& rAny ) throw (uno::RuntimeException)
650cdf0e10cSrcweir {
651cdf0e10cSrcweir switch( rAny.getValueType().getTypeClass() )
652cdf0e10cSrcweir {
653cdf0e10cSrcweir case uno::TypeClass_BOOLEAN:
654cdf0e10cSrcweir return rAny.get< bool >();
655cdf0e10cSrcweir case uno::TypeClass_FLOAT:
656cdf0e10cSrcweir return rAny.get< float >() != 0.0;
657cdf0e10cSrcweir case uno::TypeClass_DOUBLE:
658cdf0e10cSrcweir return rAny.get< double >() != 0.0;
659cdf0e10cSrcweir case uno::TypeClass_BYTE:
660cdf0e10cSrcweir case uno::TypeClass_SHORT:
661cdf0e10cSrcweir case uno::TypeClass_LONG:
662cdf0e10cSrcweir return rAny.get< sal_Int32 >() != 0;
663cdf0e10cSrcweir case uno::TypeClass_HYPER:
664cdf0e10cSrcweir return rAny.get< sal_Int64 >() != 0;
665cdf0e10cSrcweir default:;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to boolean." ) ), 0 );
668cdf0e10cSrcweir }
669cdf0e10cSrcweir
extractBoolFromAny(const uno::Any & rAny,bool bDefault)670cdf0e10cSrcweir bool extractBoolFromAny( const uno::Any& rAny, bool bDefault ) throw (uno::RuntimeException)
671cdf0e10cSrcweir {
672cdf0e10cSrcweir return rAny.hasValue() ? extractBoolFromAny( rAny ) : bDefault;
673cdf0e10cSrcweir }
674cdf0e10cSrcweir
extractStringFromAny(const uno::Any & rAny,bool bUppercaseBool)675cdf0e10cSrcweir ::rtl::OUString extractStringFromAny( const uno::Any& rAny, bool bUppercaseBool ) throw (uno::RuntimeException)
676cdf0e10cSrcweir {
677cdf0e10cSrcweir switch( rAny.getValueType().getTypeClass() )
678cdf0e10cSrcweir {
679cdf0e10cSrcweir case uno::TypeClass_STRING:
680cdf0e10cSrcweir return rAny.get< ::rtl::OUString >();
681cdf0e10cSrcweir case uno::TypeClass_BOOLEAN:
682cdf0e10cSrcweir return bUppercaseBool ?
683cdf0e10cSrcweir (rAny.get< bool >() ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TRUE" ) ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FALSE" ) )) :
684cdf0e10cSrcweir ::rtl::OUString::valueOf( (sal_Bool)rAny.get< bool >() );
685cdf0e10cSrcweir case uno::TypeClass_FLOAT:
686cdf0e10cSrcweir return ::rtl::OUString::valueOf( rAny.get< float >() );
687cdf0e10cSrcweir case uno::TypeClass_DOUBLE:
688cdf0e10cSrcweir return ::rtl::OUString::valueOf( rAny.get< double >() );
689cdf0e10cSrcweir case uno::TypeClass_BYTE:
690cdf0e10cSrcweir case uno::TypeClass_SHORT:
691cdf0e10cSrcweir case uno::TypeClass_LONG:
692cdf0e10cSrcweir return ::rtl::OUString::valueOf( rAny.get< sal_Int32 >() );
693cdf0e10cSrcweir case uno::TypeClass_HYPER:
694cdf0e10cSrcweir return ::rtl::OUString::valueOf( rAny.get< sal_Int64 >() );
695cdf0e10cSrcweir default:;
696cdf0e10cSrcweir }
697cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to string." ) ), 0 );
698cdf0e10cSrcweir }
699cdf0e10cSrcweir
extractStringFromAny(const uno::Any & rAny,const::rtl::OUString & rDefault,bool bUppercaseBool)700cdf0e10cSrcweir ::rtl::OUString extractStringFromAny( const uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool ) throw (uno::RuntimeException)
701cdf0e10cSrcweir {
702cdf0e10cSrcweir return rAny.hasValue() ? extractStringFromAny( rAny, bUppercaseBool ) : rDefault;
703cdf0e10cSrcweir }
704cdf0e10cSrcweir
getAnyAsString(const uno::Any & pvargItem)705cdf0e10cSrcweir rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir return extractStringFromAny( pvargItem );
708cdf0e10cSrcweir }
709cdf0e10cSrcweir
710cdf0e10cSrcweir
711cdf0e10cSrcweir rtl::OUString
getUniqueName(const uno::Sequence<::rtl::OUString> & _slist,const rtl::OUString & _sElementName,const::rtl::OUString & _sSuffixSeparator)712cdf0e10cSrcweir ContainerUtilities::getUniqueName( const uno::Sequence< ::rtl::OUString >& _slist, const rtl::OUString& _sElementName, const ::rtl::OUString& _sSuffixSeparator)
713cdf0e10cSrcweir {
714cdf0e10cSrcweir return getUniqueName(_slist, _sElementName, _sSuffixSeparator, sal_Int32(2));
715cdf0e10cSrcweir }
716cdf0e10cSrcweir
717cdf0e10cSrcweir rtl::OUString
getUniqueName(const uno::Sequence<rtl::OUString> & _slist,const rtl::OUString _sElementName,const rtl::OUString & _sSuffixSeparator,sal_Int32 _nStartSuffix)718cdf0e10cSrcweir ContainerUtilities::getUniqueName( const uno::Sequence< rtl::OUString >& _slist, const rtl::OUString _sElementName, const rtl::OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix)
719cdf0e10cSrcweir {
720cdf0e10cSrcweir sal_Int32 a = _nStartSuffix;
721cdf0e10cSrcweir rtl::OUString scompname = _sElementName;
722cdf0e10cSrcweir bool bElementexists = true;
723cdf0e10cSrcweir sal_Int32 nLen = _slist.getLength();
724cdf0e10cSrcweir if ( nLen == 0 )
725cdf0e10cSrcweir return _sElementName;
726cdf0e10cSrcweir
727cdf0e10cSrcweir while (bElementexists == true)
728cdf0e10cSrcweir {
729cdf0e10cSrcweir for (sal_Int32 i = 0; i < nLen; i++)
730cdf0e10cSrcweir {
731cdf0e10cSrcweir if (FieldInList(_slist, scompname) == -1)
732cdf0e10cSrcweir {
733cdf0e10cSrcweir return scompname;
734cdf0e10cSrcweir }
735cdf0e10cSrcweir }
736cdf0e10cSrcweir scompname = _sElementName + _sSuffixSeparator + rtl::OUString::valueOf( a++ );
737cdf0e10cSrcweir }
738cdf0e10cSrcweir return rtl::OUString();
739cdf0e10cSrcweir }
740cdf0e10cSrcweir
741cdf0e10cSrcweir sal_Int32
FieldInList(const uno::Sequence<rtl::OUString> & SearchList,const rtl::OUString & SearchString)742cdf0e10cSrcweir ContainerUtilities::FieldInList( const uno::Sequence< rtl::OUString >& SearchList, const rtl::OUString& SearchString )
743cdf0e10cSrcweir {
744cdf0e10cSrcweir sal_Int32 FieldLen = SearchList.getLength();
745cdf0e10cSrcweir sal_Int32 retvalue = -1;
746cdf0e10cSrcweir for (sal_Int32 i = 0; i < FieldLen; i++)
747cdf0e10cSrcweir {
748cdf0e10cSrcweir // I wonder why comparing lexicographically is done
749cdf0e10cSrcweir // when its a match is whats interesting?
750cdf0e10cSrcweir //if (SearchList[i].compareTo(SearchString) == 0)
751cdf0e10cSrcweir if ( SearchList[i].equals( SearchString ) )
752cdf0e10cSrcweir {
753cdf0e10cSrcweir retvalue = i;
754cdf0e10cSrcweir break;
755cdf0e10cSrcweir }
756cdf0e10cSrcweir }
757cdf0e10cSrcweir return retvalue;
758cdf0e10cSrcweir
759cdf0e10cSrcweir }
NeedEsc(sal_Unicode cCode)760cdf0e10cSrcweir bool NeedEsc(sal_Unicode cCode)
761cdf0e10cSrcweir {
762cdf0e10cSrcweir String sEsc(RTL_CONSTASCII_USTRINGPARAM(".^$+\\|{}()"));
763cdf0e10cSrcweir return (STRING_NOTFOUND != sEsc.Search(cCode));
764cdf0e10cSrcweir }
765cdf0e10cSrcweir
VBAToRegexp(const rtl::OUString & rIn,bool bForLike)766cdf0e10cSrcweir rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike )
767cdf0e10cSrcweir {
768cdf0e10cSrcweir rtl::OUStringBuffer sResult;
769cdf0e10cSrcweir const sal_Unicode *start = rIn.getStr();
770cdf0e10cSrcweir const sal_Unicode *end = start + rIn.getLength();
771cdf0e10cSrcweir
772cdf0e10cSrcweir int seenright = 0;
773cdf0e10cSrcweir if ( bForLike )
774cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('^'));
775cdf0e10cSrcweir
776cdf0e10cSrcweir while (start < end)
777cdf0e10cSrcweir {
778cdf0e10cSrcweir switch (*start)
779cdf0e10cSrcweir {
780cdf0e10cSrcweir case '?':
781cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('.'));
782cdf0e10cSrcweir start++;
783cdf0e10cSrcweir break;
784cdf0e10cSrcweir case '*':
785cdf0e10cSrcweir sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*")));
786cdf0e10cSrcweir start++;
787cdf0e10cSrcweir break;
788cdf0e10cSrcweir case '#':
789cdf0e10cSrcweir sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[0-9]")));
790cdf0e10cSrcweir start++;
791cdf0e10cSrcweir break;
792cdf0e10cSrcweir case '~':
793cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('\\'));
794cdf0e10cSrcweir sResult.append(*(++start));
795cdf0e10cSrcweir start++;
796cdf0e10cSrcweir break;
797cdf0e10cSrcweir // dump the ~ and escape the next characture
798cdf0e10cSrcweir case ']':
799cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('\\'));
800cdf0e10cSrcweir sResult.append(*start++);
801cdf0e10cSrcweir break;
802cdf0e10cSrcweir case '[':
803cdf0e10cSrcweir sResult.append(*start++);
804cdf0e10cSrcweir seenright = 0;
805cdf0e10cSrcweir while (start < end && !seenright)
806cdf0e10cSrcweir {
807cdf0e10cSrcweir switch (*start)
808cdf0e10cSrcweir {
809cdf0e10cSrcweir case '[':
810cdf0e10cSrcweir case '?':
811cdf0e10cSrcweir case '*':
812cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('\\'));
813cdf0e10cSrcweir sResult.append(*start);
814cdf0e10cSrcweir break;
815cdf0e10cSrcweir case ']':
816cdf0e10cSrcweir sResult.append(*start);
817cdf0e10cSrcweir seenright = 1;
818cdf0e10cSrcweir break;
819cdf0e10cSrcweir case '!':
820cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('^'));
821cdf0e10cSrcweir break;
822cdf0e10cSrcweir default:
823cdf0e10cSrcweir if (NeedEsc(*start))
824cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('\\'));
825cdf0e10cSrcweir sResult.append(*start);
826cdf0e10cSrcweir break;
827cdf0e10cSrcweir }
828cdf0e10cSrcweir start++;
829cdf0e10cSrcweir }
830cdf0e10cSrcweir break;
831cdf0e10cSrcweir default:
832cdf0e10cSrcweir if (NeedEsc(*start))
833cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('\\'));
834cdf0e10cSrcweir sResult.append(*start++);
835cdf0e10cSrcweir }
836cdf0e10cSrcweir }
837cdf0e10cSrcweir
838cdf0e10cSrcweir if ( bForLike )
839cdf0e10cSrcweir sResult.append(static_cast<sal_Unicode>('$'));
840cdf0e10cSrcweir
841cdf0e10cSrcweir return sResult.makeStringAndClear( );
842cdf0e10cSrcweir }
843cdf0e10cSrcweir
getPixelTo100thMillimeterConversionFactor(const css::uno::Reference<css::awt::XDevice> & xDevice,sal_Bool bVertical)844cdf0e10cSrcweir double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical)
845cdf0e10cSrcweir {
846cdf0e10cSrcweir double fConvertFactor = 1.0;
847cdf0e10cSrcweir if( bVertical )
848cdf0e10cSrcweir {
849cdf0e10cSrcweir fConvertFactor = xDevice->getInfo().PixelPerMeterY/100000;
850cdf0e10cSrcweir }
851cdf0e10cSrcweir else
852cdf0e10cSrcweir {
853cdf0e10cSrcweir fConvertFactor = xDevice->getInfo().PixelPerMeterX/100000;
854cdf0e10cSrcweir }
855cdf0e10cSrcweir return fConvertFactor;
856cdf0e10cSrcweir }
857cdf0e10cSrcweir
PointsToPixels(const css::uno::Reference<css::awt::XDevice> & xDevice,double fPoints,sal_Bool bVertical)858cdf0e10cSrcweir double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical)
859cdf0e10cSrcweir {
860cdf0e10cSrcweir double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical );
861cdf0e10cSrcweir return PointsToHmm( fPoints ) * fConvertFactor;
862cdf0e10cSrcweir }
PixelsToPoints(const css::uno::Reference<css::awt::XDevice> & xDevice,double fPixels,sal_Bool bVertical)863cdf0e10cSrcweir double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical)
864cdf0e10cSrcweir {
865cdf0e10cSrcweir double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical );
866cdf0e10cSrcweir return HmmToPoints( fPixels/fConvertFactor );
867cdf0e10cSrcweir }
868cdf0e10cSrcweir
PointsToHmm(double fPoints)869cdf0e10cSrcweir sal_Int32 PointsToHmm( double fPoints )
870cdf0e10cSrcweir {
871cdf0e10cSrcweir return static_cast<sal_Int32>( fPoints * factor + 0.5 );
872cdf0e10cSrcweir }
873cdf0e10cSrcweir
HmmToPoints(sal_Int32 nHmm)874cdf0e10cSrcweir double HmmToPoints( sal_Int32 nHmm )
875cdf0e10cSrcweir {
876cdf0e10cSrcweir return nHmm / factor;
877cdf0e10cSrcweir }
878cdf0e10cSrcweir
ConcreteXShapeGeometryAttributes(const css::uno::Reference<css::uno::XComponentContext> &,const css::uno::Reference<css::drawing::XShape> & xShape)879cdf0e10cSrcweir ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& /*xContext*/, const css::uno::Reference< css::drawing::XShape >& xShape )
880cdf0e10cSrcweir {
881cdf0e10cSrcweir m_pShapeHelper.reset( new ShapeHelper( xShape ) );
882cdf0e10cSrcweir }
~ConcreteXShapeGeometryAttributes()883cdf0e10cSrcweir ConcreteXShapeGeometryAttributes::~ConcreteXShapeGeometryAttributes()
884cdf0e10cSrcweir {
885cdf0e10cSrcweir }
886cdf0e10cSrcweir
getPointerStyle(const uno::Reference<frame::XModel> & xModel)887cdf0e10cSrcweir sal_Int32 getPointerStyle( const uno::Reference< frame::XModel >& xModel )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir
890cdf0e10cSrcweir sal_Int32 nPointerStyle( POINTER_ARROW );
891cdf0e10cSrcweir try
892cdf0e10cSrcweir {
893cdf0e10cSrcweir const uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
894cdf0e10cSrcweir const uno::Reference< frame::XFrame > xFrame ( xController->getFrame(), uno::UNO_SET_THROW );
895cdf0e10cSrcweir const uno::Reference< awt::XWindow > xWindow ( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
896cdf0e10cSrcweir // why the heck isn't there an XWindowPeer::getPointer, but a setPointer only?
897cdf0e10cSrcweir const Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
898cdf0e10cSrcweir if ( pWindow )
899cdf0e10cSrcweir nPointerStyle = pWindow->GetSystemWindow()->GetPointer().GetStyle();
900cdf0e10cSrcweir }
901cdf0e10cSrcweir catch( const uno::Exception& )
902cdf0e10cSrcweir {
903cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
904cdf0e10cSrcweir }
905cdf0e10cSrcweir return nPointerStyle;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir
908cdf0e10cSrcweir // #FIXME this method looks wrong, shouldn't it just affect calc *or* writer
909cdf0e10cSrcweir // document/frame/window(s) but not both ( and depending on what api called
910cdf0e10cSrcweir // this )
setCursorHelper(const uno::Reference<frame::XModel> & xModel,const Pointer & rPointer,sal_Bool bOverWrite)911cdf0e10cSrcweir void setCursorHelper( const uno::Reference< frame::XModel >& xModel, const Pointer& rPointer, sal_Bool bOverWrite )
912cdf0e10cSrcweir {
913cdf0e10cSrcweir ::std::vector< uno::Reference< frame::XController > > aControllers;
914cdf0e10cSrcweir
915cdf0e10cSrcweir uno::Reference< frame::XModel2 > xModel2( xModel, uno::UNO_QUERY );
916cdf0e10cSrcweir if ( xModel2.is() )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir const uno::Reference< container::XEnumeration > xEnumControllers( xModel2->getControllers(), uno::UNO_SET_THROW );
919cdf0e10cSrcweir while ( xEnumControllers->hasMoreElements() )
920cdf0e10cSrcweir {
921cdf0e10cSrcweir const uno::Reference< frame::XController > xController( xEnumControllers->nextElement(), uno::UNO_QUERY_THROW );
922cdf0e10cSrcweir aControllers.push_back( xController );
923cdf0e10cSrcweir }
924cdf0e10cSrcweir }
925cdf0e10cSrcweir else
926cdf0e10cSrcweir {
927cdf0e10cSrcweir if ( xModel.is() )
928cdf0e10cSrcweir {
929cdf0e10cSrcweir const uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
930cdf0e10cSrcweir aControllers.push_back( xController );
931cdf0e10cSrcweir }
932cdf0e10cSrcweir }
933cdf0e10cSrcweir
934cdf0e10cSrcweir for ( ::std::vector< uno::Reference< frame::XController > >::const_iterator controller = aControllers.begin();
935cdf0e10cSrcweir controller != aControllers.end();
936cdf0e10cSrcweir ++controller
937cdf0e10cSrcweir )
938cdf0e10cSrcweir {
939cdf0e10cSrcweir const uno::Reference< frame::XFrame > xFrame ( (*controller)->getFrame(), uno::UNO_SET_THROW );
940cdf0e10cSrcweir const uno::Reference< awt::XWindow > xWindow ( xFrame->getContainerWindow(), uno::UNO_SET_THROW );
941cdf0e10cSrcweir
942cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
943cdf0e10cSrcweir OSL_ENSURE( pWindow, "ScVbaApplication::setCursor: no window!" );
944cdf0e10cSrcweir if ( !pWindow )
945cdf0e10cSrcweir continue;
946cdf0e10cSrcweir
947cdf0e10cSrcweir pWindow->GetSystemWindow()->SetPointer( rPointer );
948cdf0e10cSrcweir pWindow->GetSystemWindow()->EnableChildPointerOverwrite( bOverWrite );
949cdf0e10cSrcweir }
950cdf0e10cSrcweir }
951cdf0e10cSrcweir
setDefaultPropByIntrospection(const uno::Any & aObj,const uno::Any & aValue)952cdf0e10cSrcweir void setDefaultPropByIntrospection( const uno::Any& aObj, const uno::Any& aValue ) throw ( uno::RuntimeException )
953cdf0e10cSrcweir {
954cdf0e10cSrcweir uno::Reference< beans::XIntrospectionAccess > xUnoAccess( getIntrospectionAccess( aObj ) );
955cdf0e10cSrcweir
956cdf0e10cSrcweir // #MAYBE #FIXME sort of a bit of a hack,
957cdf0e10cSrcweir uno::Reference< script::XDefaultProperty > xDflt( aObj, uno::UNO_QUERY_THROW );
958cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet;
959cdf0e10cSrcweir
960cdf0e10cSrcweir if ( xUnoAccess.is() )
961cdf0e10cSrcweir xPropSet.set( xUnoAccess->queryAdapter( ::getCppuType( (const uno::Reference< beans::XPropertySet > *)0 ) ), uno::UNO_QUERY);
962cdf0e10cSrcweir
963cdf0e10cSrcweir if ( xPropSet.is() )
964cdf0e10cSrcweir xPropSet->setPropertyValue( xDflt->getDefaultPropertyName(), aValue );
965cdf0e10cSrcweir else
966cdf0e10cSrcweir throw uno::RuntimeException();
967cdf0e10cSrcweir }
968cdf0e10cSrcweir
getPropertyValue(const uno::Sequence<beans::PropertyValue> & aProp,const rtl::OUString & aName)969cdf0e10cSrcweir uno::Any getPropertyValue( const uno::Sequence< beans::PropertyValue >& aProp, const rtl::OUString& aName )
970cdf0e10cSrcweir {
971cdf0e10cSrcweir uno::Any result;
972cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
973cdf0e10cSrcweir {
974cdf0e10cSrcweir if ( aProp[i].Name.equals(aName) )
975cdf0e10cSrcweir {
976cdf0e10cSrcweir aProp[i].Value >>= result;
977cdf0e10cSrcweir return result;
978cdf0e10cSrcweir }
979cdf0e10cSrcweir }
980cdf0e10cSrcweir return result;
981cdf0e10cSrcweir }
982cdf0e10cSrcweir
setPropertyValue(uno::Sequence<beans::PropertyValue> & aProp,const rtl::OUString & aName,const uno::Any & aValue)983cdf0e10cSrcweir sal_Bool setPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, const rtl::OUString& aName, const uno::Any& aValue )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aProp.getLength(); i++ )
986cdf0e10cSrcweir {
987cdf0e10cSrcweir if ( aProp[i].Name.equals(aName) )
988cdf0e10cSrcweir {
989cdf0e10cSrcweir aProp[i].Value = aValue;
990cdf0e10cSrcweir return sal_True;
991cdf0e10cSrcweir }
992cdf0e10cSrcweir }
993cdf0e10cSrcweir return sal_False;
994cdf0e10cSrcweir }
995cdf0e10cSrcweir
996cdf0e10cSrcweir // ====UserFormGeomentryHelper====
997cdf0e10cSrcweir //---------------------------------------------
UserFormGeometryHelper(const uno::Reference<uno::XComponentContext> &,const uno::Reference<awt::XControl> & xControl,double fOffsetX,double fOffsetY)998cdf0e10cSrcweir UserFormGeometryHelper::UserFormGeometryHelper(
999cdf0e10cSrcweir const uno::Reference< uno::XComponentContext >& /*xContext*/,
1000cdf0e10cSrcweir const uno::Reference< awt::XControl >& xControl,
1001cdf0e10cSrcweir double fOffsetX, double fOffsetY ) :
1002cdf0e10cSrcweir mfOffsetX( fOffsetX ),
1003cdf0e10cSrcweir mfOffsetY( fOffsetY ),
1004cdf0e10cSrcweir mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() )
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir if ( !xControl.is() )
1007cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No control is provided!" ) ),
1008cdf0e10cSrcweir uno::Reference< uno::XInterface >() );
1009cdf0e10cSrcweir
1010cdf0e10cSrcweir mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW );
1011cdf0e10cSrcweir mxModelProps.set( xControl->getModel(), uno::UNO_QUERY_THROW );
1012cdf0e10cSrcweir mxUnitConv.set( mxWindow, uno::UNO_QUERY_THROW );
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir
getLeft() const1015cdf0e10cSrcweir double UserFormGeometryHelper::getLeft() const
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir return implGetPos( false );
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir
setLeft(double fLeft)1020cdf0e10cSrcweir void UserFormGeometryHelper::setLeft( double fLeft )
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir implSetPos( fLeft, false );
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir
getTop() const1025cdf0e10cSrcweir double UserFormGeometryHelper::getTop() const
1026cdf0e10cSrcweir {
1027cdf0e10cSrcweir return implGetPos( true );
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir
setTop(double fTop)1030cdf0e10cSrcweir void UserFormGeometryHelper::setTop( double fTop )
1031cdf0e10cSrcweir {
1032cdf0e10cSrcweir implSetPos( fTop, true );
1033cdf0e10cSrcweir }
1034cdf0e10cSrcweir
getWidth() const1035cdf0e10cSrcweir double UserFormGeometryHelper::getWidth() const
1036cdf0e10cSrcweir {
1037cdf0e10cSrcweir return implGetSize( false, true );
1038cdf0e10cSrcweir }
1039cdf0e10cSrcweir
setWidth(double fWidth)1040cdf0e10cSrcweir void UserFormGeometryHelper::setWidth( double fWidth )
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir implSetSize( fWidth, false, true );
1043cdf0e10cSrcweir }
1044cdf0e10cSrcweir
getHeight() const1045cdf0e10cSrcweir double UserFormGeometryHelper::getHeight() const
1046cdf0e10cSrcweir {
1047cdf0e10cSrcweir return implGetSize( true, true );
1048cdf0e10cSrcweir }
1049cdf0e10cSrcweir
setHeight(double fHeight)1050cdf0e10cSrcweir void UserFormGeometryHelper::setHeight( double fHeight )
1051cdf0e10cSrcweir {
1052cdf0e10cSrcweir implSetSize( fHeight, true, true );
1053cdf0e10cSrcweir }
1054cdf0e10cSrcweir
getInnerWidth() const1055cdf0e10cSrcweir double UserFormGeometryHelper::getInnerWidth() const
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir return implGetSize( false, false );
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir
setInnerWidth(double fWidth)1060cdf0e10cSrcweir void UserFormGeometryHelper::setInnerWidth( double fWidth )
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir implSetSize( fWidth, false, false );
1063cdf0e10cSrcweir }
1064cdf0e10cSrcweir
getInnerHeight() const1065cdf0e10cSrcweir double UserFormGeometryHelper::getInnerHeight() const
1066cdf0e10cSrcweir {
1067cdf0e10cSrcweir return implGetSize( true, false );
1068cdf0e10cSrcweir }
1069cdf0e10cSrcweir
setInnerHeight(double fHeight)1070cdf0e10cSrcweir void UserFormGeometryHelper::setInnerHeight( double fHeight )
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir implSetSize( fHeight, true, false );
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir
getOffsetX() const1075cdf0e10cSrcweir double UserFormGeometryHelper::getOffsetX() const
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir return mfOffsetX;
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir
getOffsetY() const1080cdf0e10cSrcweir double UserFormGeometryHelper::getOffsetY() const
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir return mfOffsetY;
1083cdf0e10cSrcweir }
1084cdf0e10cSrcweir
1085cdf0e10cSrcweir // ----------------------------------------------------------------------------
1086cdf0e10cSrcweir
1087cdf0e10cSrcweir static const ::rtl::OUString saPosXName( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) );
1088cdf0e10cSrcweir static const ::rtl::OUString saPosYName( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) );
1089cdf0e10cSrcweir static const ::rtl::OUString saWidthName( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
1090cdf0e10cSrcweir static const ::rtl::OUString saHeightName( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
1091cdf0e10cSrcweir
implGetPos(bool bPosY) const1092cdf0e10cSrcweir double UserFormGeometryHelper::implGetPos( bool bPosY ) const
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir sal_Int32 nPosAppFont = mxModelProps->getPropertyValue( bPosY ? saPosYName : saPosXName ).get< sal_Int32 >();
1095cdf0e10cSrcweir // appfont to pixel
1096cdf0e10cSrcweir awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosAppFont, nPosAppFont ), util::MeasureUnit::APPFONT );
1097cdf0e10cSrcweir // pixel to VBA points
1098cdf0e10cSrcweir awt::Point aPosPoint = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::POINT );
1099cdf0e10cSrcweir return bPosY ? (aPosPoint.Y - mfOffsetY) : (aPosPoint.X - mfOffsetX);
1100cdf0e10cSrcweir }
1101cdf0e10cSrcweir
implSetPos(double fPos,bool bPosY)1102cdf0e10cSrcweir void UserFormGeometryHelper::implSetPos( double fPos, bool bPosY )
1103cdf0e10cSrcweir {
1104cdf0e10cSrcweir // convert passed VBA points to pixels
1105cdf0e10cSrcweir sal_Int32 nPosPixel = static_cast< sal_Int32 >( fPos + (bPosY ? mfOffsetY : mfOffsetX) );
1106cdf0e10cSrcweir awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosPixel, nPosPixel ), util::MeasureUnit::POINT );
1107cdf0e10cSrcweir // pixel to appfont
1108cdf0e10cSrcweir awt::Point aPosAppFont = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::APPFONT );
1109cdf0e10cSrcweir mxModelProps->setPropertyValue( bPosY ? saPosYName : saPosXName, uno::Any( bPosY ? aPosAppFont.Y : aPosAppFont.X ) );
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir
implGetSize(bool bHeight,bool bOuter) const1112cdf0e10cSrcweir double UserFormGeometryHelper::implGetSize( bool bHeight, bool bOuter ) const
1113cdf0e10cSrcweir {
1114cdf0e10cSrcweir sal_Int32 nSizeAppFont = mxModelProps->getPropertyValue( bHeight ? saHeightName : saWidthName ).get< sal_Int32 >();
1115cdf0e10cSrcweir // appfont to pixel
1116cdf0e10cSrcweir awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSizeAppFont, nSizeAppFont ), util::MeasureUnit::APPFONT );
1117cdf0e10cSrcweir
1118cdf0e10cSrcweir /* The VBA symbols 'Width' and 'Height' return the outer size including
1119cdf0e10cSrcweir window decoration (in difference to the symbols 'InnerWidth' and
1120cdf0e10cSrcweir 'InnerHeight'), but the window API returns the inner size. */
1121cdf0e10cSrcweir if( mbDialog && bOuter )
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) )
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL );
1126cdf0e10cSrcweir aSizePixel = awt::Size( aOuterRect.getWidth(), aOuterRect.getHeight() );
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir }
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir // pixel to VBA points
1131cdf0e10cSrcweir awt::Size aSizePoint = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::POINT );
1132cdf0e10cSrcweir return bHeight ? aSizePoint.Height : aSizePoint.Width;
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir
implSetSize(double fSize,bool bHeight,bool bOuter)1135cdf0e10cSrcweir void UserFormGeometryHelper::implSetSize( double fSize, bool bHeight, bool bOuter )
1136cdf0e10cSrcweir {
1137cdf0e10cSrcweir // convert passed VBA points to pixels
1138cdf0e10cSrcweir sal_Int32 nSize = static_cast< sal_Int32 >( fSize );
1139cdf0e10cSrcweir awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSize, nSize ), util::MeasureUnit::POINT );
1140cdf0e10cSrcweir
1141cdf0e10cSrcweir /* The VBA symbols 'Width' and 'Height' set the outer size (in difference
1142cdf0e10cSrcweir to the symbols 'InnerWidth' and 'InnerHeight'), but the dialog model
1143cdf0e10cSrcweir expects the inner size. We have to remove the window extents from the
1144cdf0e10cSrcweir pixel height to get the same result. */
1145cdf0e10cSrcweir if ( mbDialog && bOuter )
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) )
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL );
1150cdf0e10cSrcweir if( !aOuterRect.IsEmpty() )
1151cdf0e10cSrcweir {
1152cdf0e10cSrcweir awt::Rectangle aInnerRect = mxWindow->getPosSize();
1153cdf0e10cSrcweir sal_Int32 nDecorWidth = aOuterRect.getWidth() - aInnerRect.Width;
1154cdf0e10cSrcweir sal_Int32 nDecorHeight = aOuterRect.getHeight() - aInnerRect.Height;
1155cdf0e10cSrcweir aSizePixel.Width = ::std::max< sal_Int32 >( aSizePixel.Width - nDecorWidth, 1 );
1156cdf0e10cSrcweir aSizePixel.Height = ::std::max< sal_Int32 >( aSizePixel.Height - nDecorHeight, 1 );
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir }
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir
1161cdf0e10cSrcweir awt::Size aSizeAppFont = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::APPFONT );
1162cdf0e10cSrcweir mxModelProps->setPropertyValue( bHeight ? saHeightName : saWidthName, uno::Any( bHeight ? aSizeAppFont.Height : aSizeAppFont.Width ) );
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir
1165cdf0e10cSrcweir // ============================================================================
1166cdf0e10cSrcweir
getLeft() const1167cdf0e10cSrcweir double ConcreteXShapeGeometryAttributes::getLeft() const
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir return m_pShapeHelper->getLeft();
1170cdf0e10cSrcweir }
setLeft(double nLeft)1171cdf0e10cSrcweir void ConcreteXShapeGeometryAttributes::setLeft( double nLeft )
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir m_pShapeHelper->setLeft( nLeft );
1174cdf0e10cSrcweir }
getTop() const1175cdf0e10cSrcweir double ConcreteXShapeGeometryAttributes::getTop() const
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir return m_pShapeHelper->getTop();
1178cdf0e10cSrcweir }
setTop(double nTop)1179cdf0e10cSrcweir void ConcreteXShapeGeometryAttributes::setTop( double nTop )
1180cdf0e10cSrcweir {
1181cdf0e10cSrcweir m_pShapeHelper->setTop( nTop );
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir
getHeight() const1184cdf0e10cSrcweir double ConcreteXShapeGeometryAttributes::getHeight() const
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir return m_pShapeHelper->getHeight();
1187cdf0e10cSrcweir }
setHeight(double nHeight)1188cdf0e10cSrcweir void ConcreteXShapeGeometryAttributes::setHeight( double nHeight )
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir m_pShapeHelper->setHeight( nHeight );
1191cdf0e10cSrcweir }
getWidth() const1192cdf0e10cSrcweir double ConcreteXShapeGeometryAttributes::getWidth() const
1193cdf0e10cSrcweir {
1194cdf0e10cSrcweir return m_pShapeHelper->getWidth();
1195cdf0e10cSrcweir }
setWidth(double nWidth)1196cdf0e10cSrcweir void ConcreteXShapeGeometryAttributes::setWidth( double nWidth)
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir m_pShapeHelper->setWidth( nWidth );
1199cdf0e10cSrcweir }
1200cdf0e10cSrcweir
1201cdf0e10cSrcweir
ShapeHelper(const css::uno::Reference<css::drawing::XShape> & _xShape)1202cdf0e10cSrcweir ShapeHelper::ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ) : xShape( _xShape )
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir if( !xShape.is() )
1205cdf0e10cSrcweir throw css::uno::RuntimeException( rtl::OUString::createFromAscii("No valid shape for helper"), css::uno::Reference< css::uno::XInterface >() );
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir
getHeight() const1208cdf0e10cSrcweir double ShapeHelper::getHeight() const
1209cdf0e10cSrcweir {
1210cdf0e10cSrcweir return Millimeter::getInPoints(xShape->getSize().Height);
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir
1213cdf0e10cSrcweir
setHeight(double _fheight)1214cdf0e10cSrcweir void ShapeHelper::setHeight(double _fheight) throw ( css::script::BasicErrorException )
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir try
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir css::awt::Size aSize = xShape->getSize();
1219cdf0e10cSrcweir aSize.Height = Millimeter::getInHundredthsOfOneMillimeter(_fheight);
1220cdf0e10cSrcweir xShape->setSize(aSize);
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir catch ( css::uno::Exception& /*e*/)
1223cdf0e10cSrcweir {
1224cdf0e10cSrcweir throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
1225cdf0e10cSrcweir }
1226cdf0e10cSrcweir }
1227cdf0e10cSrcweir
1228cdf0e10cSrcweir
getWidth() const1229cdf0e10cSrcweir double ShapeHelper::getWidth() const
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir return Millimeter::getInPoints(xShape->getSize().Width);
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir
setWidth(double _fWidth)1234cdf0e10cSrcweir void ShapeHelper::setWidth(double _fWidth) throw ( css::script::BasicErrorException )
1235cdf0e10cSrcweir {
1236cdf0e10cSrcweir try
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir css::awt::Size aSize = xShape->getSize();
1239cdf0e10cSrcweir aSize.Width = Millimeter::getInHundredthsOfOneMillimeter(_fWidth);
1240cdf0e10cSrcweir xShape->setSize(aSize);
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir catch (css::uno::Exception& /*e*/)
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir }
1247cdf0e10cSrcweir
1248cdf0e10cSrcweir
getLeft() const1249cdf0e10cSrcweir double ShapeHelper::getLeft() const
1250cdf0e10cSrcweir {
1251cdf0e10cSrcweir return Millimeter::getInPoints(xShape->getPosition().X);
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir
1254cdf0e10cSrcweir
setLeft(double _fLeft)1255cdf0e10cSrcweir void ShapeHelper::setLeft(double _fLeft)
1256cdf0e10cSrcweir {
1257cdf0e10cSrcweir css::awt::Point aPoint = xShape->getPosition();
1258cdf0e10cSrcweir aPoint.X = Millimeter::getInHundredthsOfOneMillimeter(_fLeft);
1259cdf0e10cSrcweir xShape->setPosition(aPoint);
1260cdf0e10cSrcweir }
1261cdf0e10cSrcweir
1262cdf0e10cSrcweir
getTop() const1263cdf0e10cSrcweir double ShapeHelper::getTop() const
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir return Millimeter::getInPoints(xShape->getPosition().Y);
1266cdf0e10cSrcweir }
1267cdf0e10cSrcweir
1268cdf0e10cSrcweir
setTop(double _fTop)1269cdf0e10cSrcweir void ShapeHelper::setTop(double _fTop)
1270cdf0e10cSrcweir {
1271cdf0e10cSrcweir css::awt::Point aPoint = xShape->getPosition();
1272cdf0e10cSrcweir aPoint.Y = Millimeter::getInHundredthsOfOneMillimeter(_fTop);
1273cdf0e10cSrcweir xShape->setPosition(aPoint);
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir
exception(const rtl::OUString & DetailedMessage,const css::uno::Exception & ex,int err,const rtl::OUString &)1276cdf0e10cSrcweir void DebugHelper::exception( const rtl::OUString& DetailedMessage, const css::uno::Exception& ex, int err, const rtl::OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException )
1277cdf0e10cSrcweir {
1278cdf0e10cSrcweir // #TODO #FIXME ( do we want to support additionalArg here )
1279cdf0e10cSrcweir throw css::script::BasicErrorException( DetailedMessage.concat( rtl::OUString::createFromAscii(" ") ).concat( ex.Message ), css::uno::Reference< css::uno::XInterface >(), err, rtl::OUString() );
1280cdf0e10cSrcweir }
1281cdf0e10cSrcweir
exception(int err,const rtl::OUString & additionalArgument)1282cdf0e10cSrcweir void DebugHelper::exception( int err, const rtl::OUString& additionalArgument ) throw( css::script::BasicErrorException )
1283cdf0e10cSrcweir {
1284cdf0e10cSrcweir exception( rtl::OUString(), css::uno::Exception(), err, additionalArgument );
1285cdf0e10cSrcweir }
exception(css::uno::Exception & ex)1286cdf0e10cSrcweir void DebugHelper::exception( css::uno::Exception& ex ) throw( css::script::BasicErrorException )
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir exception( rtl::OUString(), ex, SbERR_INTERNAL_ERROR, rtl::OUString() );
1289cdf0e10cSrcweir }
1290cdf0e10cSrcweir
Millimeter()1291cdf0e10cSrcweir Millimeter::Millimeter():m_nMillimeter(0) {}
1292cdf0e10cSrcweir
Millimeter(double mm)1293cdf0e10cSrcweir Millimeter::Millimeter(double mm):m_nMillimeter(mm) {}
1294cdf0e10cSrcweir
set(double mm)1295cdf0e10cSrcweir void Millimeter::set(double mm) { m_nMillimeter = mm; }
setInPoints(double points)1296cdf0e10cSrcweir void Millimeter::setInPoints(double points)
1297cdf0e10cSrcweir {
1298cdf0e10cSrcweir m_nMillimeter = points * factor / 100.0;
1299cdf0e10cSrcweir }
1300cdf0e10cSrcweir
setInHundredthsOfOneMillimeter(double hmm)1301cdf0e10cSrcweir void Millimeter::setInHundredthsOfOneMillimeter(double hmm)
1302cdf0e10cSrcweir {
1303cdf0e10cSrcweir m_nMillimeter = hmm / 100;
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir
get()1306cdf0e10cSrcweir double Millimeter::get()
1307cdf0e10cSrcweir {
1308cdf0e10cSrcweir return m_nMillimeter;
1309cdf0e10cSrcweir }
getInHundredthsOfOneMillimeter()1310cdf0e10cSrcweir double Millimeter::getInHundredthsOfOneMillimeter()
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir return m_nMillimeter * 100;
1313cdf0e10cSrcweir }
getInPoints()1314cdf0e10cSrcweir double Millimeter::getInPoints()
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir return m_nMillimeter / factor * 100.0;
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir
getInHundredthsOfOneMillimeter(double points)1319cdf0e10cSrcweir sal_Int32 Millimeter::getInHundredthsOfOneMillimeter(double points)
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir sal_Int32 mm = static_cast<sal_Int32>(points * factor);
1322cdf0e10cSrcweir return mm;
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir
getInPoints(int _hmm)1325cdf0e10cSrcweir double Millimeter::getInPoints(int _hmm)
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir double points = double( static_cast<double>(_hmm) / factor);
1328cdf0e10cSrcweir return points;
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir
getVBADocument(const uno::Reference<frame::XModel> & xModel)1331cdf0e10cSrcweir uno::Reference< XHelperInterface > getVBADocument( const uno::Reference< frame::XModel >& xModel )
1332cdf0e10cSrcweir {
1333cdf0e10cSrcweir uno::Reference< XHelperInterface > xIf;
1334cdf0e10cSrcweir try
1335cdf0e10cSrcweir {
1336cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY_THROW );
1337cdf0e10cSrcweir ::rtl::OUString aCodeName;
1338cdf0e10cSrcweir xDocProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ) >>= aCodeName;
1339cdf0e10cSrcweir xIf = getUnoDocModule( aCodeName, getSfxObjShell( xModel ) );
1340cdf0e10cSrcweir }
1341cdf0e10cSrcweir catch( uno::Exception& )
1342cdf0e10cSrcweir {
1343cdf0e10cSrcweir }
1344cdf0e10cSrcweir return xIf;
1345cdf0e10cSrcweir }
1346cdf0e10cSrcweir
getUnoDocModule(const String & aModName,SfxObjectShell * pShell)1347cdf0e10cSrcweir uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell )
1348cdf0e10cSrcweir {
1349cdf0e10cSrcweir uno::Reference< XHelperInterface > xIf;
1350cdf0e10cSrcweir if ( pShell )
1351cdf0e10cSrcweir {
1352cdf0e10cSrcweir rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") );
1353cdf0e10cSrcweir BasicManager* pBasMgr = pShell->GetBasicManager();
1354cdf0e10cSrcweir if ( pBasMgr && pBasMgr->GetName().Len() )
1355cdf0e10cSrcweir sProj = pBasMgr->GetName();
1356cdf0e10cSrcweir if( StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ) )
1357cdf0e10cSrcweir if( SbModule* pMod = pBasic->FindModule( aModName ) )
1358cdf0e10cSrcweir xIf.set( pMod->GetUnoModule(), uno::UNO_QUERY );
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir return xIf;
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir
getSfxObjShell(const uno::Reference<frame::XModel> & xModel)1363cdf0e10cSrcweir SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException)
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir SfxObjectShell* pFoundShell = NULL;
1366cdf0e10cSrcweir if ( xModel.is() )
1367cdf0e10cSrcweir {
1368cdf0e10cSrcweir uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW );
1369cdf0e10cSrcweir pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId()));
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir if ( !pFoundShell )
1372cdf0e10cSrcweir throw uno::RuntimeException();
1373cdf0e10cSrcweir return pFoundShell;
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir } // openoffice
1377cdf0e10cSrcweir } //org
1378