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