1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include <cppuhelper/bootstrap.hxx> 28 #include <com/sun/star/util/XURLTransformer.hpp> 29 #include <com/sun/star/frame/XDispatchProvider.hpp> 30 #include <com/sun/star/frame/XModel.hpp> 31 #include <com/sun/star/frame/XFrame.hpp> 32 #include <com/sun/star/frame/XDesktop.hpp> 33 #include <com/sun/star/frame/XController.hpp> 34 #include <com/sun/star/uno/XComponentContext.hpp> 35 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 36 #include <com/sun/star/beans/XPropertySet.hpp> 37 #include <com/sun/star/beans/XIntrospection.hpp> 38 39 #include <comphelper/processfactory.hxx> 40 41 #include <sfx2/objsh.hxx> 42 #include <sfx2/viewfrm.hxx> 43 #include <sfx2/dispatch.hxx> 44 #include <sfx2/app.hxx> 45 #include <svl/stritem.hxx> 46 47 #include <docuno.hxx> 48 49 #include <basic/sbx.hxx> 50 #include <basic/sbstar.hxx> 51 #include <rtl/math.hxx> 52 53 #include <math.h> 54 #include "vbahelper.hxx" 55 #include "tabvwsh.hxx" 56 #include "transobj.hxx" 57 #include "scmod.hxx" 58 #include "vbashape.hxx" 59 #include "unonames.hxx" 60 #include "cellsuno.hxx" 61 using namespace ::com::sun::star; 62 using namespace ::ooo::vba; 63 64 #define POINTTO100THMILLIMETERFACTOR 35.27778 65 void unoToSbxValue( SbxVariable* pVar, const uno::Any& aValue ); 66 67 uno::Any sbxToUnoValue( SbxVariable* pVar ); 68 69 70 namespace ooo 71 { 72 namespace vba 73 { 74 75 const double Millimeter::factor = 35.27778; 76 77 uno::Reference< beans::XIntrospectionAccess > 78 getIntrospectionAccess( const uno::Any& aObject ) throw (uno::RuntimeException) 79 { 80 static uno::Reference< beans::XIntrospection > xIntrospection; 81 if( !xIntrospection.is() ) 82 { 83 uno::Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); 84 xIntrospection.set( xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection") ), uno::UNO_QUERY_THROW ); 85 } 86 return xIntrospection->inspect( aObject ); 87 } 88 89 uno::Reference< script::XTypeConverter > 90 getTypeConverter( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) 91 { 92 static uno::Reference< script::XTypeConverter > xTypeConv( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter") ), xContext ), uno::UNO_QUERY_THROW ); 93 return xTypeConv; 94 } 95 // helper method to determine if the view ( calc ) is in print-preview mode 96 bool isInPrintPreview( SfxViewFrame* pView ) 97 { 98 sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0; 99 if ( pView->GetObjectShell()->GetFactory().GetViewFactoryCount() > 100 nViewNo && !pView->GetObjectShell()->IsInPlaceActive() ) 101 { 102 SfxViewFactory &rViewFactory = 103 pView->GetObjectShell()->GetFactory().GetViewFactory(nViewNo); 104 if ( pView->GetCurViewId() == rViewFactory.GetOrdinal() ) 105 return true; 106 } 107 return false; 108 } 109 const ::rtl::OUString REPLACE_CELLS_WARNING( RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning")); 110 const uno::Any& 111 aNULL() 112 { 113 static uno::Any aNULLL = uno::makeAny( uno::Reference< uno::XInterface >() ); 114 return aNULLL; 115 } 116 117 class PasteCellsWarningReseter 118 { 119 private: 120 bool bInitialWarningState; 121 static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException ) 122 { 123 static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); 124 static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); 125 static uno::Reference<lang::XMultiComponentFactory > xServiceManager( 126 xContext->getServiceManager(), uno::UNO_QUERY_THROW ); 127 static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW ); 128 return xProps; 129 } 130 131 bool getReplaceCellsWarning() throw ( uno::RuntimeException ) 132 { 133 sal_Bool res = sal_False; 134 getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING ) >>= res; 135 return ( res == sal_True ); 136 } 137 138 void setReplaceCellsWarning( bool bState ) throw ( uno::RuntimeException ) 139 { 140 getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING, uno::makeAny( bState ) ); 141 } 142 public: 143 PasteCellsWarningReseter() throw ( uno::RuntimeException ) 144 { 145 bInitialWarningState = getReplaceCellsWarning(); 146 if ( bInitialWarningState ) 147 setReplaceCellsWarning( false ); 148 } 149 ~PasteCellsWarningReseter() 150 { 151 if ( bInitialWarningState ) 152 { 153 // don't allow dtor to throw 154 try 155 { 156 setReplaceCellsWarning( true ); 157 } 158 catch ( uno::Exception& /*e*/ ){} 159 } 160 } 161 }; 162 163 void dispatchExecute(css::uno::Reference< css::frame::XModel>& xModel, sal_uInt16 nSlot, SfxCallMode nCall) 164 { 165 ScTabViewShell* pViewShell = getBestViewShell( xModel ); 166 SfxViewFrame* pViewFrame = NULL; 167 if ( pViewShell ) 168 pViewFrame = pViewShell->GetViewFrame(); 169 if ( pViewFrame ) 170 { 171 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); 172 if( pDispatcher ) 173 { 174 pDispatcher->Execute( nSlot , nCall ); 175 } 176 } 177 } 178 179 void 180 implnPaste() 181 { 182 PasteCellsWarningReseter resetWarningBox; 183 ScTabViewShell* pViewShell = getCurrentBestViewShell(); 184 if ( pViewShell ) 185 { 186 pViewShell->PasteFromSystem(); 187 pViewShell->CellContentChanged(); 188 } 189 } 190 191 192 void 193 implnCopy() 194 { 195 ScTabViewShell* pViewShell = getCurrentBestViewShell(); 196 if ( pViewShell ) 197 pViewShell->CopyToClip(NULL,false,false,true); 198 } 199 200 void 201 implnCut() 202 { 203 ScTabViewShell* pViewShell = getCurrentBestViewShell(); 204 if ( pViewShell ) 205 pViewShell->CutToClip( NULL, sal_True ); 206 } 207 208 void implnPasteSpecial(sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose) 209 { 210 PasteCellsWarningReseter resetWarningBox; 211 sal_Bool bAsLink(sal_False), bOtherDoc(sal_False); 212 InsCellCmd eMoveMode = INS_NONE; 213 214 ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell(); 215 if ( !pTabViewShell ) 216 // none active, try next best 217 pTabViewShell = getCurrentBestViewShell(); 218 if ( pTabViewShell ) 219 { 220 ScViewData* pView = pTabViewShell->GetViewData(); 221 Window* pWin = ( pView != NULL ) ? pView->GetActiveWin() : NULL; 222 if ( pView && pWin ) 223 { 224 if ( bAsLink && bOtherDoc ) 225 pTabViewShell->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK 226 else 227 { 228 ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin ); 229 ScDocument* pDoc = NULL; 230 if ( pOwnClip ) 231 pDoc = pOwnClip->GetDocument(); 232 pTabViewShell->PasteFromClip( nFlags, pDoc, 233 nFunction, bSkipEmpty, bTranspose, bAsLink, 234 eMoveMode, IDF_NONE, sal_True ); 235 pTabViewShell->CellContentChanged(); 236 } 237 } 238 } 239 240 } 241 242 uno::Reference< frame::XModel > 243 getCurrentDocument() throw (uno::RuntimeException) 244 { 245 uno::Reference< frame::XModel > xModel; 246 SbxObject* pBasic = dynamic_cast< SbxObject* > ( SFX_APP()->GetBasic() ); 247 SbxObject* basicChosen = pBasic ; 248 if ( basicChosen == NULL) 249 { 250 OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" ); 251 return xModel; 252 } 253 SbxObject* p = pBasic; 254 SbxObject* pParent = p->GetParent(); 255 SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL; 256 257 if( pParentParent ) 258 { 259 basicChosen = pParentParent; 260 } 261 else if( pParent ) 262 { 263 basicChosen = pParent; 264 } 265 266 267 uno::Any aModel; 268 SbxVariable *pCompVar = basicChosen->Find( UniString(RTL_CONSTASCII_USTRINGPARAM("ThisComponent")), SbxCLASS_OBJECT ); 269 270 if ( pCompVar ) 271 { 272 aModel = sbxToUnoValue( pCompVar ); 273 if ( sal_False == ( aModel >>= xModel ) || 274 !xModel.is() ) 275 { 276 // trying last gasp try the current component 277 uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); 278 // test if vba service is present 279 uno::Reference< uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); 280 uno::Reference<lang::XMultiComponentFactory > xSMgr( xCtx->getServiceManager(), uno::UNO_QUERY_THROW ); 281 uno::Reference< frame::XDesktop > xDesktop (xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx), uno::UNO_QUERY_THROW ); 282 xModel.set( xDesktop->getCurrentComponent(), uno::UNO_QUERY ); 283 if ( !xModel.is() ) 284 { 285 throw uno::RuntimeException( 286 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract model from basic ( its obviously not set yet ) therefore don't know the currently selected document") ), uno::Reference< uno::XInterface >() ); 287 } 288 return xModel; 289 } 290 else 291 { 292 OSL_TRACE("Have model ThisComponent points to url %s", 293 ::rtl::OUStringToOString( xModel->getURL(), 294 RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 295 } 296 } 297 else 298 { 299 OSL_TRACE("Failed to get ThisComponent"); 300 throw uno::RuntimeException( 301 rtl::OUString( 302 RTL_CONSTASCII_USTRINGPARAM( 303 "Can't determine the currently selected document") ), 304 uno::Reference< uno::XInterface >() ); 305 } 306 return xModel; 307 } 308 309 ScDocShell* 310 getDocShell( css::uno::Reference< css::frame::XModel>& xModel ) 311 { 312 uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW ); 313 ScModelObj* pModel = dynamic_cast< ScModelObj* >( xIf.get() ); 314 ScDocShell* pDocShell = NULL; 315 if ( pModel ) 316 pDocShell = (ScDocShell*)pModel->GetEmbeddedObject(); 317 return pDocShell; 318 319 } 320 321 ScTabViewShell* 322 getBestViewShell( css::uno::Reference< css::frame::XModel>& xModel ) 323 { 324 ScDocShell* pDocShell = getDocShell( xModel ); 325 if ( pDocShell ) 326 return pDocShell->GetBestViewShell(); 327 return NULL; 328 } 329 330 ScTabViewShell* 331 getCurrentBestViewShell() 332 { 333 uno::Reference< frame::XModel > xModel = getCurrentDocument(); 334 return getBestViewShell( xModel ); 335 } 336 337 SfxViewFrame* 338 getCurrentViewFrame() 339 { 340 ScTabViewShell* pViewShell = getCurrentBestViewShell(); 341 if ( pViewShell ) 342 return pViewShell->GetViewFrame(); 343 return NULL; 344 } 345 346 sal_Int32 347 OORGBToXLRGB( sal_Int32 nCol ) 348 { 349 sal_Int32 nRed = nCol; 350 nRed &= 0x00FF0000; 351 nRed >>= 16; 352 sal_Int32 nGreen = nCol; 353 nGreen &= 0x0000FF00; 354 nGreen >>= 8; 355 sal_Int32 nBlue = nCol; 356 nBlue &= 0x000000FF; 357 sal_Int32 nRGB = ( (nBlue << 16) | (nGreen << 8) | nRed ); 358 return nRGB; 359 } 360 sal_Int32 361 XLRGBToOORGB( sal_Int32 nCol ) 362 { 363 sal_Int32 nBlue = nCol; 364 nBlue &= 0x00FF0000; 365 nBlue >>= 16; 366 sal_Int32 nGreen = nCol; 367 nGreen &= 0x0000FF00; 368 nGreen >>= 8; 369 sal_Int32 nRed = nCol; 370 nRed &= 0x000000FF; 371 sal_Int32 nRGB = ( (nRed << 16) | (nGreen << 8) | nBlue ); 372 return nRGB; 373 } 374 uno::Any 375 OORGBToXLRGB( const uno::Any& aCol ) 376 { 377 sal_Int32 nCol=0; 378 aCol >>= nCol; 379 nCol = OORGBToXLRGB( nCol ); 380 return uno::makeAny( nCol ); 381 } 382 uno::Any 383 XLRGBToOORGB( const uno::Any& aCol ) 384 { 385 sal_Int32 nCol=0; 386 aCol >>= nCol; 387 nCol = XLRGBToOORGB( nCol ); 388 return uno::makeAny( nCol ); 389 } 390 391 void PrintOutHelper( 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, css::uno::Reference< frame::XModel >& xModel, sal_Bool bUseSelection ) 392 { 393 sal_Int32 nTo = 0; 394 sal_Int32 nFrom = 0; 395 sal_Int16 nCopies = 1; 396 sal_Bool bPreview = sal_False; 397 sal_Bool bCollate = sal_False; 398 sal_Bool bSelection = bUseSelection; 399 From >>= nFrom; 400 To >>= nTo; 401 Copies >>= nCopies; 402 Preview >>= bPreview; 403 if ( nCopies > 1 ) // Collate only useful when more that 1 copy 404 Collate >>= bCollate; 405 406 rtl::OUString sRange( RTL_CONSTASCII_USTRINGPARAM( "-" ) ); 407 rtl::OUString sFileName; 408 409 if (( nFrom || nTo ) ) 410 { 411 if ( nFrom ) 412 sRange = ( ::rtl::OUString::valueOf( nFrom ) + sRange ); 413 if ( nTo ) 414 sRange += ::rtl::OUString::valueOf( nTo ); 415 } 416 417 if ( PrToFileName.getValue() ) 418 { 419 PrToFileName >>= sFileName; 420 } 421 ScTabViewShell* pViewShell = getBestViewShell( xModel ); 422 SfxViewFrame* pViewFrame = NULL; 423 if ( pViewShell ) 424 pViewFrame = pViewShell->GetViewFrame(); 425 if ( pViewFrame ) 426 { 427 SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 428 429 SfxBoolItem sfxCollate( SID_PRINT_COLLATE, bCollate ); 430 aArgs.Put( sfxCollate, sfxCollate.Which() ); 431 SfxInt16Item sfxCopies( SID_PRINT_COPIES, nCopies ); 432 aArgs.Put( sfxCopies, sfxCopies.Which() ); 433 if ( sFileName.getLength() ) 434 { 435 SfxStringItem sfxFileName( SID_FILE_NAME, sFileName); 436 aArgs.Put( sfxFileName, sfxFileName.Which() ); 437 438 } 439 if ( sRange.getLength() ) 440 { 441 SfxStringItem sfxRange( SID_PRINT_PAGES, sRange ); 442 aArgs.Put( sfxRange, sfxRange.Which() ); 443 } 444 SfxBoolItem sfxSelection( SID_SELECTION, bSelection ); 445 aArgs.Put( sfxSelection, sfxSelection.Which() ); 446 SfxBoolItem sfxAsync( SID_ASYNCHRON, sal_False ); 447 aArgs.Put( sfxAsync, sfxAsync.Which() ); 448 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); 449 450 if ( pDispatcher ) 451 { 452 if ( bPreview ) 453 { 454 if ( !pViewFrame->GetFrame().IsInPlace() ) 455 { 456 SC_MOD()->InputEnterHandler(); 457 pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_SYNCHRON ); 458 while ( isInPrintPreview( pViewFrame ) ) 459 Application::Yield(); 460 } 461 } 462 else 463 pDispatcher->Execute( (sal_uInt16)SID_PRINTDOC, (SfxCallMode)SFX_CALLMODE_SYNCHRON, aArgs ); 464 } 465 466 } 467 468 // #FIXME #TODO 469 // 1 ActivePrinter ( how/can we switch a printer via API? ) 470 // 2 PrintToFile ( ms behaviour if this option is specified but no 471 // filename supplied 'PrToFileName' then the user will be prompted ) 472 // 3 Need to check behaviour of Selected sheets with range ( e.g. From & To 473 // values ) in oOO these options are mutually exclusive 474 // 4 There is a pop up to do with transparent objects in the print source 475 // should be able to disable that via configuration for the duration 476 // of this method 477 } 478 479 void PrintPreviewHelper( const css::uno::Any& /*EnableChanges*/, css::uno::Reference< css::frame::XModel >& xModel ) 480 { 481 dispatchExecute( xModel, SID_VIEWSHELL1 ); 482 } 483 484 rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) 485 { 486 uno::Type aType = pvargItem.getValueType(); 487 uno::TypeClass eTypeClass = aType.getTypeClass(); 488 rtl::OUString sString; 489 switch ( eTypeClass ) 490 { 491 case uno::TypeClass_BOOLEAN: 492 { 493 sal_Bool bBool = sal_False; 494 pvargItem >>= bBool; 495 sString = rtl::OUString::valueOf( bBool ); 496 break; 497 } 498 case uno::TypeClass_STRING: 499 pvargItem >>= sString; 500 break; 501 case uno::TypeClass_FLOAT: 502 { 503 float aFloat = 0; 504 pvargItem >>= aFloat; 505 sString = rtl::OUString::valueOf( aFloat ); 506 break; 507 } 508 case uno::TypeClass_DOUBLE: 509 { 510 double aDouble = 0; 511 pvargItem >>= aDouble; 512 sString = rtl::OUString::valueOf( aDouble ); 513 break; 514 } 515 case uno::TypeClass_SHORT: 516 case uno::TypeClass_LONG: 517 case uno::TypeClass_BYTE: 518 { 519 sal_Int32 aNum = 0; 520 pvargItem >>= aNum; 521 sString = rtl::OUString::valueOf( aNum ); 522 break; 523 } 524 525 case uno::TypeClass_HYPER: 526 { 527 sal_Int64 aHyper = 0; 528 pvargItem >>= aHyper; 529 sString = rtl::OUString::valueOf( aHyper ); 530 break; 531 } 532 default: 533 throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid type, can't convert" ), uno::Reference< uno::XInterface >() ); 534 } 535 return sString; 536 } 537 538 539 rtl::OUString 540 ContainerUtilities::getUniqueName( const uno::Sequence< ::rtl::OUString >& _slist, const rtl::OUString& _sElementName, const ::rtl::OUString& _sSuffixSeparator) 541 { 542 return getUniqueName(_slist, _sElementName, _sSuffixSeparator, sal_Int32(2)); 543 } 544 545 rtl::OUString 546 ContainerUtilities::getUniqueName( const uno::Sequence< rtl::OUString >& _slist, const rtl::OUString _sElementName, const rtl::OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix) 547 { 548 sal_Int32 a = _nStartSuffix; 549 rtl::OUString scompname = _sElementName; 550 bool bElementexists = true; 551 sal_Int32 nLen = _slist.getLength(); 552 if ( nLen == 0 ) 553 return _sElementName; 554 555 while (bElementexists == true) 556 { 557 for (sal_Int32 i = 0; i < nLen; i++) 558 { 559 if (FieldInList(_slist, scompname) == -1) 560 { 561 return scompname; 562 } 563 } 564 scompname = _sElementName + _sSuffixSeparator + rtl::OUString::valueOf( a++ ); 565 } 566 return rtl::OUString(); 567 } 568 569 sal_Int32 570 ContainerUtilities::FieldInList( const uno::Sequence< rtl::OUString >& SearchList, const rtl::OUString& SearchString ) 571 { 572 sal_Int32 FieldLen = SearchList.getLength(); 573 sal_Int32 retvalue = -1; 574 for (sal_Int32 i = 0; i < FieldLen; i++) 575 { 576 // I wonder why comparing lexicographically is done 577 // when its a match is whats interesting? 578 //if (SearchList[i].compareTo(SearchString) == 0) 579 if ( SearchList[i].equals( SearchString ) ) 580 { 581 retvalue = i; 582 break; 583 } 584 } 585 return retvalue; 586 587 } 588 bool NeedEsc(sal_Unicode cCode) 589 { 590 String sEsc(RTL_CONSTASCII_USTRINGPARAM(".^$+\\|{}()")); 591 return (STRING_NOTFOUND != sEsc.Search(cCode)); 592 } 593 594 rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike ) 595 { 596 rtl::OUStringBuffer sResult; 597 const sal_Unicode *start = rIn.getStr(); 598 const sal_Unicode *end = start + rIn.getLength(); 599 600 int seenright = 0; 601 if ( bForLike ) 602 sResult.append(static_cast<sal_Unicode>('^')); 603 604 while (start < end) 605 { 606 switch (*start) 607 { 608 case '?': 609 sResult.append(static_cast<sal_Unicode>('.')); 610 start++; 611 break; 612 case '*': 613 sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*"))); 614 start++; 615 break; 616 case '#': 617 sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[0-9]"))); 618 start++; 619 break; 620 case '~': 621 sResult.append(static_cast<sal_Unicode>('\\')); 622 sResult.append(*(++start)); 623 start++; 624 break; 625 // dump the ~ and escape the next characture 626 case ']': 627 sResult.append(static_cast<sal_Unicode>('\\')); 628 sResult.append(*start++); 629 break; 630 case '[': 631 sResult.append(*start++); 632 seenright = 0; 633 while (start < end && !seenright) 634 { 635 switch (*start) 636 { 637 case '[': 638 case '?': 639 case '*': 640 sResult.append(static_cast<sal_Unicode>('\\')); 641 sResult.append(*start); 642 break; 643 case ']': 644 sResult.append(*start); 645 seenright = 1; 646 break; 647 case '!': 648 sResult.append(static_cast<sal_Unicode>('^')); 649 break; 650 default: 651 if (NeedEsc(*start)) 652 sResult.append(static_cast<sal_Unicode>('\\')); 653 sResult.append(*start); 654 break; 655 } 656 start++; 657 } 658 break; 659 default: 660 if (NeedEsc(*start)) 661 sResult.append(static_cast<sal_Unicode>('\\')); 662 sResult.append(*start++); 663 } 664 } 665 666 if ( bForLike ) 667 sResult.append(static_cast<sal_Unicode>('$')); 668 669 return sResult.makeStringAndClear( ); 670 } 671 672 double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) 673 { 674 double fConvertFactor = 1.0; 675 if( bVertical ) 676 { 677 fConvertFactor = xDevice->getInfo().PixelPerMeterY/100000; 678 } 679 else 680 { 681 fConvertFactor = xDevice->getInfo().PixelPerMeterX/100000; 682 } 683 return fConvertFactor; 684 } 685 686 double PointsToPixels( css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) 687 { 688 double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); 689 return fPoints * POINTTO100THMILLIMETERFACTOR * fConvertFactor; 690 } 691 double PixelsToPoints( css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) 692 { 693 double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); 694 return (fPixels/fConvertFactor)/POINTTO100THMILLIMETERFACTOR; 695 } 696 697 ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape ) 698 { 699 m_xShape = new ScVbaShape( xContext, xShape ); 700 } 701 702 #define VBA_LEFT "PositionX" 703 #define VBA_TOP "PositionY" 704 UserFormGeometryHelper::UserFormGeometryHelper( const uno::Reference< uno::XComponentContext >& /*xContext*/, const uno::Reference< awt::XControl >& xControl ) 705 { 706 mxModel.set( xControl->getModel(), uno::UNO_QUERY_THROW ); 707 } 708 double UserFormGeometryHelper::getLeft() 709 { 710 sal_Int32 nLeft = 0; 711 mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_LEFT ) ) ) >>= nLeft; 712 return Millimeter::getInPoints( nLeft ); 713 } 714 void UserFormGeometryHelper::setLeft( double nLeft ) 715 { 716 mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_LEFT ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nLeft ) ) ); 717 } 718 double UserFormGeometryHelper::getTop() 719 { 720 sal_Int32 nTop = 0; 721 mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_TOP ) ) ) >>= nTop; 722 return Millimeter::getInPoints( nTop ); 723 } 724 void UserFormGeometryHelper::setTop( double nTop ) 725 { 726 mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_TOP ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nTop ) ) ); 727 } 728 double UserFormGeometryHelper::getHeight() 729 { 730 sal_Int32 nHeight = 0; 731 mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHGT ) ) ) >>= nHeight; 732 return Millimeter::getInPoints( nHeight ); 733 } 734 void UserFormGeometryHelper::setHeight( double nHeight ) 735 { 736 mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHGT ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nHeight ) ) ); 737 } 738 double UserFormGeometryHelper::getWidth() 739 { 740 sal_Int32 nWidth = 0; 741 mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLWID ) ) ) >>= nWidth; 742 return Millimeter::getInPoints( nWidth ); 743 } 744 void UserFormGeometryHelper::setWidth( double nWidth) 745 { 746 mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLWID ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nWidth ) ) ); 747 } 748 749 SfxItemSet* 750 ScVbaCellRangeAccess::GetDataSet( ScCellRangeObj* pRangeObj ) 751 { 752 SfxItemSet* pDataSet = pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : NULL ; 753 return pDataSet; 754 755 } 756 757 } // vba 758 } // ooo 759