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