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