1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <stdio.h>
#include "tools/fsys.hxx"
#include "tools/getprocessworkingdir.hxx"
#include <tools/solarmutex.hxx>
#include "osl/process.h"
#include "rtl/ustrbuf.hxx"
#include "vcl/svapp.hxx"
#include "vcl/window.hxx"
#include "vcl/timer.hxx"
#include "vcl/solarmutex.hxx"
#include "ios/saldata.hxx"
#include "ios/salinst.h"
#include "ios/salframe.h"
#include "ios/salobj.h"
#include "ios/salsys.h"
#include "ios/salvd.h"
#include "ios/salbmp.h"
#include "ios/salprn.h"
#include "ios/saltimer.h"
#include "ios/vcluiapp.h"
#include "print.h"
#include "impbmp.hxx"
#include "salimestatus.hxx"
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
#include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
using namespace std;
using namespace ::com::sun::star;
extern sal_Bool ImplSVMain();
static int* gpnInit = 0;
static bool bNoSVMain = true;
// -----------------------------------------------------------------------
class IosDelayedSettingsChanged : public Timer
{
bool mbInvalidate;
public:
IosDelayedSettingsChanged( bool bInvalidate ) :
mbInvalidate( bInvalidate )
{
}
virtual void Timeout()
{
SalData* pSalData = GetSalData();
if( ! pSalData->maFrames.empty() )
pSalData->maFrames.front()->CallCallback( SALEVENT_SETTINGSCHANGED, NULL );
if( mbInvalidate )
{
for( std::list< IosSalFrame* >::iterator it = pSalData->maFrames.begin();
it != pSalData->maFrames.end(); ++it )
{
if( (*it)->mbShown )
(*it)->SendPaintEvent( NULL );
}
}
Stop();
delete this;
}
};
void IosSalInstance::delayedSettingsChanged( bool bInvalidate )
{
osl::SolarGuard aGuard( *mpSalYieldMutex );
IosDelayedSettingsChanged* pTimer = new IosDelayedSettingsChanged( bInvalidate );
pTimer->SetTimeout( 50 );
pTimer->Start();
}
// the AppEventList must be available before any SalData/SalInst/etc. objects are ready
typedef std::list<const ApplicationEvent*> AppEventList;
AppEventList IosSalInstance::aAppEventList;
// initialize the VCL_UIApplication object
static void initUIApp()
{
[VCL_UIApplication sharedApplication];
SalData::ensureThreadAutoreleasePool();
}
sal_Bool ImplSVMainHook( int * pnInit )
{
char sMain[] = "main";
gpnInit = pnInit;
bNoSVMain = false;
initUIApp();
char* pArgv[] = { sMain, NULL };
UIApplicationMain( 1, pArgv, NULL, NULL );
return TRUE; // indicate that ImplSVMainHook is implemented
}
// =======================================================================
void SalAbort( const XubString& rErrorText, bool bDumpCore )
{
if( !rErrorText.Len() )
fprintf( stderr, "Application Error " );
else
fprintf( stderr, "%s ",
ByteString( rErrorText, osl_getThreadTextEncoding() ).GetBuffer() );
if( bDumpCore )
abort();
else
_exit(1);
}
// -----------------------------------------------------------------------
void InitSalData()
{
SalData *pSalData = new SalData;
SetSalData( pSalData );
}
// -----------------------------------------------------------------------
const ::rtl::OUString& SalGetDesktopEnvironment()
{
static OUString aDesktopEnvironment(RTL_CONSTASCII_USTRINGPARAM( "CocoaTouch" ));
return aDesktopEnvironment;
}
// -----------------------------------------------------------------------
void DeInitSalData()
{
SalData *pSalData = GetSalData();
delete pSalData;
SetSalData( NULL );
}
// -----------------------------------------------------------------------
void InitSalMain()
{
rtl::OUString urlWorkDir;
rtl_uString *sysWorkDir = NULL;
if (tools::getProcessWorkingDir(urlWorkDir))
{
oslFileError err2 = osl_getSystemPathFromFileURL(urlWorkDir.pData, &sysWorkDir);
if (err2 == osl_File_E_None)
{
ByteString aPath( getenv( "PATH" ) );
ByteString aResPath( getenv( "STAR_RESOURCEPATH" ) );
ByteString aCmdPath( OUStringToOString(OUString(sysWorkDir), RTL_TEXTENCODING_UTF8).getStr() );
ByteString aTmpPath;
// Get absolute path of command's directory
if ( aCmdPath.Len() ) {
DirEntry aCmdDirEntry( aCmdPath );
aCmdDirEntry.ToAbs();
aCmdPath = ByteString( aCmdDirEntry.GetPath().GetFull(), RTL_TEXTENCODING_ASCII_US );
}
// Assign to PATH environment variable
if ( aCmdPath.Len() )
{
aTmpPath = ByteString( "PATH=" );
aTmpPath += aCmdPath;
if ( aPath.Len() )
aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US );
aTmpPath += aPath;
putenv( (char*)aTmpPath.GetBuffer() );
}
// Assign to STAR_RESOURCEPATH environment variable
if ( aCmdPath.Len() )
{
aTmpPath = ByteString( "STAR_RESOURCEPATH=" );
aTmpPath += aCmdPath;
if ( aResPath.Len() )
aTmpPath += ByteString( DirEntry::GetSearchDelimiter(), RTL_TEXTENCODING_ASCII_US );
aTmpPath += aResPath;
putenv( (char*)aTmpPath.GetBuffer() );
}
}
}
}
// -----------------------------------------------------------------------
void DeInitSalMain()
{
}
// =======================================================================
SalYieldMutex::SalYieldMutex()
{
mnCount = 0;
mnThreadId = 0;
}
void SalYieldMutex::acquire()
{
SolarMutexObject::acquire();
mnThreadId = osl::Thread::getCurrentIdentifier();
mnCount++;
}
void SalYieldMutex::release()
{
if ( mnThreadId == osl::Thread::getCurrentIdentifier() )
{
if ( mnCount == 1 )
mnThreadId = 0;
mnCount--;
}
SolarMutexObject::release();
}
sal_Bool SalYieldMutex::tryToAcquire()
{
if ( SolarMutexObject::tryToAcquire() )
{
mnThreadId = osl::Thread::getCurrentIdentifier();
mnCount++;
return sal_True;
}
else
return sal_False;
}
// -----------------------------------------------------------------------
// some convenience functions regarding the yield mutex, aka solar mutex
sal_Bool ImplSalYieldMutexTryToAcquire()
{
IosSalInstance* pInst = (IosSalInstance*) GetSalData()->mpFirstInstance;
if ( pInst )
return pInst->mpSalYieldMutex->tryToAcquire();
else
return FALSE;
}
void ImplSalYieldMutexAcquire()
{
IosSalInstance* pInst = (IosSalInstance*) GetSalData()->mpFirstInstance;
if ( pInst )
pInst->mpSalYieldMutex->acquire();
}
void ImplSalYieldMutexRelease()
{
IosSalInstance* pInst = (IosSalInstance*) GetSalData()->mpFirstInstance;
if ( pInst )
pInst->mpSalYieldMutex->release();
}
// =======================================================================
SalInstance* CreateSalInstance()
{
// this is the case for not using SVMain
// not so good
if( bNoSVMain )
initUIApp();
SalData* pSalData = GetSalData();
DBG_ASSERT( pSalData->mpFirstInstance == NULL, "more than one instance created" );
IosSalInstance* pInst = new IosSalInstance;
// init instance (only one instance in this version !!!)
pSalData->mpFirstInstance = pInst;
// this one is for outside IosSalInstance::Yield
SalData::ensureThreadAutoreleasePool();
// no focus rects on NWF ios
ImplGetSVData()->maNWFData.mbNoFocusRects = true;
ImplGetSVData()->maNWFData.mbNoBoldTabFocus = true;
ImplGetSVData()->maNWFData.mbNoActiveTabTextRaise = true;
ImplGetSVData()->maNWFData.mbCenteredTabs = true;
ImplGetSVData()->maNWFData.mbProgressNeedsErase = true;
ImplGetSVData()->maNWFData.mbCheckBoxNeedsErase = true;
ImplGetSVData()->maNWFData.mnStatusBarLowerRightOffset = 10;
ImplGetSVData()->maGDIData.mbNoXORClipping = true;
ImplGetSVData()->maWinData.mbNoSaveBackground = true;
return pInst;
}
// -----------------------------------------------------------------------
void DestroySalInstance( SalInstance* pInst )
{
delete pInst;
}
// -----------------------------------------------------------------------
IosSalInstance::IosSalInstance()
{
mpSalYieldMutex = new SalYieldMutex;
mpSalYieldMutex->acquire();
::tools::SolarMutex::SetSolarMutex( mpSalYieldMutex );
maMainThread = osl::Thread::getCurrentIdentifier();
mbWaitingYield = false;
maUserEventListMutex = osl_createMutex();
mnActivePrintJobs = 0;
maWaitingYieldCond = osl_createCondition();
}
// -----------------------------------------------------------------------
IosSalInstance::~IosSalInstance()
{
::tools::SolarMutex::SetSolarMutex( 0 );
mpSalYieldMutex->release();
delete mpSalYieldMutex;
osl_destroyMutex( maUserEventListMutex );
osl_destroyCondition( maWaitingYieldCond );
}
// -----------------------------------------------------------------------
void IosSalInstance::wakeupYield()
{
}
// -----------------------------------------------------------------------
void IosSalInstance::PostUserEvent( IosSalFrame* pFrame, sal_uInt16 nType, void* pData )
{
osl_acquireMutex( maUserEventListMutex );
maUserEvents.push_back( SalUserEvent( pFrame, pData, nType ) );
osl_releaseMutex( maUserEventListMutex );
// notify main loop that an event has arrived
wakeupYield();
}
// -----------------------------------------------------------------------
osl::SolarMutex* IosSalInstance::GetYieldMutex()
{
return mpSalYieldMutex;
}
// -----------------------------------------------------------------------
sal_uLong IosSalInstance::ReleaseYieldMutex()
{
SalYieldMutex* pYieldMutex = mpSalYieldMutex;
if ( pYieldMutex->GetThreadId() ==
osl::Thread::getCurrentIdentifier() )
{
sal_uLong nCount = pYieldMutex->GetAcquireCount();
sal_uLong n = nCount;
while ( n )
{
pYieldMutex->release();
n--;
}
return nCount;
}
else
return 0;
}
// -----------------------------------------------------------------------
void IosSalInstance::AcquireYieldMutex( sal_uLong nCount )
{
SalYieldMutex* pYieldMutex = mpSalYieldMutex;
while ( nCount )
{
pYieldMutex->acquire();
nCount--;
}
}
// -----------------------------------------------------------------------
bool IosSalInstance::CheckYieldMutex()
{
bool bRet = true;
SalYieldMutex* pYieldMutex = mpSalYieldMutex;
if ( pYieldMutex->GetThreadId() != osl::Thread::getCurrentIdentifier())
{
bRet = false;
}
return bRet;
}
// -----------------------------------------------------------------------
bool IosSalInstance::isUIAppThread() const
{
return osl::Thread::getCurrentIdentifier() == maMainThread;
}
// -----------------------------------------------------------------------
class ReleasePoolHolder
{
NSAutoreleasePool* mpPool;
public:
ReleasePoolHolder() : mpPool( [[NSAutoreleasePool alloc] init] ) {}
~ReleasePoolHolder() { [mpPool release]; }
};
void IosSalInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
{
// ensure that the per thread autorelease pool is top level and
// will therefore not be destroyed by cocoa implicitly
SalData::ensureThreadAutoreleasePool();
// NSAutoreleasePool documentation suggests we should have
// an own pool for each yield level
ReleasePoolHolder aReleasePool;
// Release all locks so that we don't deadlock when we pull pending
// events from the event queue
bool bDispatchUser = true;
while( bDispatchUser )
{
sal_uLong nCount = ReleaseYieldMutex();
// get one user event
osl_acquireMutex( maUserEventListMutex );
SalUserEvent aEvent( NULL, NULL, 0 );
if( ! maUserEvents.empty() )
{
aEvent = maUserEvents.front();
maUserEvents.pop_front();
}
else
bDispatchUser = false;
osl_releaseMutex( maUserEventListMutex );
AcquireYieldMutex( nCount );
// dispatch it
if( aEvent.mpFrame && IosSalFrame::isAlive( aEvent.mpFrame ) )
{
aEvent.mpFrame->CallCallback( aEvent.mnType, aEvent.mpData );
osl_setCondition( maWaitingYieldCond );
// return if only one event is asked for
if( ! bHandleAllCurrentEvents )
return;
}
}
// handle event queue
// events mye be only handled in the thread the app was created
if( mnActivePrintJobs == 0 )
{
// we need to be woken up by a cocoa-event
// if a user event should be posted by the event handling below
bool bOldWaitingYield = mbWaitingYield;
mbWaitingYield = bWait;
mbWaitingYield = bOldWaitingYield;
// collect update rectangles
const std::list< IosSalFrame* > rFrames( GetSalData()->maFrames );
for( std::list< IosSalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
{
if( (*it)->mbShown && ! (*it)->maInvalidRect.IsEmpty() )
{
(*it)->Flush( (*it)->maInvalidRect );
(*it)->maInvalidRect.SetEmpty();
}
}
osl_setCondition( maWaitingYieldCond );
}
}
// -----------------------------------------------------------------------
bool IosSalInstance::AnyInput( sal_uInt16 nType )
{
if( nType & VCL_INPUT_APPEVENT )
{
if( ! aAppEventList.empty() )
return true;
if( nType == VCL_INPUT_APPEVENT )
return false;
}
if( nType & VCL_INPUT_TIMER )
{
if( IosSalTimer::pRunningTimer )
{
NSDate* pDt = [IosSalTimer::pRunningTimer fireDate];
if( pDt && [pDt timeIntervalSinceNow] < 0 )
{
return true;
}
}
}
return false;
}
// -----------------------------------------------------------------------
SalFrame* IosSalInstance::CreateChildFrame( SystemParentData*, sal_uLong /*nSalFrameStyle*/ )
{
return NULL;
}
// -----------------------------------------------------------------------
SalFrame* IosSalInstance::CreateFrame( SalFrame* pParent, sal_uLong nSalFrameStyle )
{
SalData::ensureThreadAutoreleasePool();
SalFrame* pFrame = new IosSalFrame( pParent, nSalFrameStyle );
return pFrame;
}
// -----------------------------------------------------------------------
void IosSalInstance::DestroyFrame( SalFrame* pFrame )
{
delete pFrame;
}
// -----------------------------------------------------------------------
SalObject* IosSalInstance::CreateObject( SalFrame* pParent, SystemWindowData* /* pWindowData */, sal_Bool /* bShow */ )
{
// SystemWindowData is meaningless on Mac OS X
IosSalObject *pObject = NULL;
if ( pParent )
pObject = new IosSalObject( static_cast<IosSalFrame*>(pParent) );
return pObject;
}
// -----------------------------------------------------------------------
void IosSalInstance::DestroyObject( SalObject* pObject )
{
delete ( pObject );
}
// -----------------------------------------------------------------------
SalPrinter* IosSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
{
(void) pInfoPrinter;
return NULL;
}
// -----------------------------------------------------------------------
void IosSalInstance::DestroyPrinter( SalPrinter* pPrinter )
{
delete pPrinter;
}
// -----------------------------------------------------------------------
void IosSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
{
// ???
(void) pList;
}
// -----------------------------------------------------------------------
void IosSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
{
// ???
}
// -----------------------------------------------------------------------
void IosSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
{
delete pInfo;
}
// -----------------------------------------------------------------------
XubString IosSalInstance::GetDefaultPrinter()
{
// #i113170# may not be the main thread if called from UNO API
SalData::ensureThreadAutoreleasePool();
// ???
return maDefaultPrinter;
}
// -----------------------------------------------------------------------
SalInfoPrinter* IosSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
ImplJobSetup* pSetupData )
{
(void) pQueueInfo;
(void) pSetupData;
// #i113170# may not be the main thread if called from UNO API
SalData::ensureThreadAutoreleasePool();
SalInfoPrinter* pNewInfoPrinter = NULL;
// ???
return pNewInfoPrinter;
}
// -----------------------------------------------------------------------
void IosSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
{
// #i113170# may not be the main thread if called from UNO API
SalData::ensureThreadAutoreleasePool();
delete pPrinter;
}
// -----------------------------------------------------------------------
SalSystem* IosSalInstance::CreateSystem()
{
return new IosSalSystem();
}
// -----------------------------------------------------------------------
void IosSalInstance::DestroySystem( SalSystem* pSystem )
{
delete pSystem;
}
// -----------------------------------------------------------------------
void IosSalInstance::SetEventCallback( void*, bool(*)(void*,void*,int) )
{
}
// -----------------------------------------------------------------------
void IosSalInstance::SetErrorEventCallback( void*, bool(*)(void*,void*,int) )
{
}
// -----------------------------------------------------------------------
void* IosSalInstance::GetConnectionIdentifier( ConnectionIdentifierType& rReturnedType, int& rReturnedBytes )
{
rReturnedBytes = 1;
rReturnedType = AsciiCString;
return (void*)"";
}
void IosSalInstance::AddToRecentDocumentList(const rtl::OUString& /*rFileUrl*/, const rtl::OUString& /*rMimeType*/)
{
}
// -----------------------------------------------------------------------
SalTimer* IosSalInstance::CreateSalTimer()
{
return new IosSalTimer();
}
// -----------------------------------------------------------------------
SalSystem* IosSalInstance::CreateSalSystem()
{
return new IosSalSystem();
}
// -----------------------------------------------------------------------
SalBitmap* IosSalInstance::CreateSalBitmap()
{
return new IosSalBitmap();
}
// -----------------------------------------------------------------------
SalSession* IosSalInstance::CreateSalSession()
{
return NULL;
}
// -----------------------------------------------------------------------
SalI18NImeStatus* IosSalInstance::CreateI18NImeStatus()
{
// ???
return NULL;
}
// -----------------------------------------------------------------------
// YieldMutexReleaser
YieldMutexReleaser::YieldMutexReleaser() : mnCount( 0 )
{
SalData* pSalData = GetSalData();
if( ! pSalData->mpFirstInstance->isUIAppThread() )
{
SalData::ensureThreadAutoreleasePool();
mnCount = pSalData->mpFirstInstance->ReleaseYieldMutex();
}
}
YieldMutexReleaser::~YieldMutexReleaser()
{
if( mnCount != 0 )
GetSalData()->mpFirstInstance->AcquireYieldMutex( mnCount );
}
//////////////////////////////////////////////////////////////
rtl::OUString GetOUString( CFStringRef rStr )
{
if( rStr == 0 )
return rtl::OUString();
CFIndex nLength = CFStringGetLength( rStr );
if( nLength == 0 )
return rtl::OUString();
const UniChar* pConstStr = CFStringGetCharactersPtr( rStr );
if( pConstStr )
return rtl::OUString( pConstStr, nLength );
UniChar* pStr = reinterpret_cast<UniChar*>( rtl_allocateMemory( sizeof(UniChar)*nLength ) );
CFRange aRange = { 0, nLength };
CFStringGetCharacters( rStr, aRange, pStr );
rtl::OUString aRet( pStr, nLength );
rtl_freeMemory( pStr );
return aRet;
}
rtl::OUString GetOUString( NSString* pStr )
{
if( ! pStr )
return rtl::OUString();
int nLen = [pStr length];
if( nLen == 0 )
return rtl::OUString();
rtl::OUStringBuffer aBuf( nLen+1 );
aBuf.setLength( nLen );
[pStr getCharacters: const_cast<sal_Unicode*>(aBuf.getStr())];
return aBuf.makeStringAndClear();
}
CFStringRef CreateCFString( const rtl::OUString& rStr )
{
return CFStringCreateWithCharacters(kCFAllocatorDefault, rStr.getStr(), rStr.getLength() );
}
NSString* CreateNSString( const rtl::OUString& rStr )
{
return [[NSString alloc] initWithCharacters: rStr.getStr() length: rStr.getLength()];
}
CGImageRef CreateCGImage( const Image& rImage )
{
BitmapEx aBmpEx( rImage.GetBitmapEx() );
Bitmap aBmp( aBmpEx.GetBitmap() );
if( ! aBmp || ! aBmp.ImplGetImpBitmap() )
return NULL;
// simple case, no transparency
IosSalBitmap* pSalBmp = static_cast<IosSalBitmap*>(aBmp.ImplGetImpBitmap()->ImplGetSalBitmap());
if( ! pSalBmp )
return NULL;
CGImageRef xImage = NULL;
if( ! (aBmpEx.IsAlpha() || aBmpEx.IsTransparent() ) )
xImage = pSalBmp->CreateCroppedImage( 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else if( aBmpEx.IsAlpha() )
{
AlphaMask aAlphaMask( aBmpEx.GetAlpha() );
Bitmap aMask( aAlphaMask.GetBitmap() );
IosSalBitmap* pMaskBmp = static_cast<IosSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
if( pMaskBmp )
xImage = pSalBmp->CreateWithMask( *pMaskBmp, 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else
xImage = pSalBmp->CreateCroppedImage( 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
}
else if( aBmpEx.GetTransparentType() == TRANSPARENT_BITMAP )
{
Bitmap aMask( aBmpEx.GetMask() );
IosSalBitmap* pMaskBmp = static_cast<IosSalBitmap*>(aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
if( pMaskBmp )
xImage = pSalBmp->CreateWithMask( *pMaskBmp, 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
else
xImage = pSalBmp->CreateCroppedImage( 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight );
}
else if( aBmpEx.GetTransparentType() == TRANSPARENT_COLOR )
{
Color aTransColor( aBmpEx.GetTransparentColor() );
SalColor nTransColor = MAKE_SALCOLOR( aTransColor.GetRed(), aTransColor.GetGreen(), aTransColor.GetBlue() );
xImage = pSalBmp->CreateColorMask( 0, 0, pSalBmp->mnWidth, pSalBmp->mnHeight, nTransColor );
}
return xImage;
}
UIImage* CreateNSImage( const Image& rImage )
{
CGImageRef xImage = CreateCGImage( rImage );
if( ! xImage )
return nil;
Size aSize( rImage.GetSizePixel() );
UIImage* pImage = [[UIImage alloc] initWithCGImage: xImage];
CGImageRelease( xImage );
return pImage;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|