1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_canvas.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "dx_config.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 35*cdf0e10cSrcweir #include <comphelper/anytostring.hxx> 36*cdf0e10cSrcweir #include <basegfx/vector/b2ivector.hxx> 37*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace com::sun::star; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace dxcanvas 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir DXCanvasItem::DXCanvasItem() : 44*cdf0e10cSrcweir ConfigItem( 45*cdf0e10cSrcweir ::rtl::OUString( 46*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "Office.Canvas/DXCanvas" )), 47*cdf0e10cSrcweir CONFIG_MODE_IMMEDIATE_UPDATE ), 48*cdf0e10cSrcweir maValues(), 49*cdf0e10cSrcweir maMaxTextureSize(), 50*cdf0e10cSrcweir mbBlacklistCurrentDevice(false), 51*cdf0e10cSrcweir mbValuesDirty(false) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir try 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aName(1); 56*cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DeviceBlacklist" )); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir uno::Sequence< uno::Any > aProps( GetProperties( aName )); 59*cdf0e10cSrcweir uno::Sequence< sal_Int32 > aValues; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir if( aProps.getLength() > 0 && 62*cdf0e10cSrcweir (aProps[0] >>= aValues) ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir const sal_Int32* pValues = aValues.getConstArray(); 65*cdf0e10cSrcweir const sal_Int32 nNumEntries( aValues.getLength()*sizeof(sal_Int32)/sizeof(DeviceInfo) ); 66*cdf0e10cSrcweir for( sal_Int32 i=0; i<nNumEntries; ++i ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir DeviceInfo aInfo; 69*cdf0e10cSrcweir aInfo.nVendorId = *pValues++; 70*cdf0e10cSrcweir aInfo.nDeviceId = *pValues++; 71*cdf0e10cSrcweir aInfo.nDeviceSubSysId = *pValues++; 72*cdf0e10cSrcweir aInfo.nDeviceRevision = *pValues++; 73*cdf0e10cSrcweir aInfo.nDriverId = *pValues++; 74*cdf0e10cSrcweir aInfo.nDriverVersion = *pValues++; 75*cdf0e10cSrcweir aInfo.nDriverSubVersion = *pValues++; 76*cdf0e10cSrcweir aInfo.nDriverBuildId = *pValues++; 77*cdf0e10cSrcweir maValues.insert(aInfo); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlacklistCurrentDevice" )); 82*cdf0e10cSrcweir aProps = GetProperties( aName ); 83*cdf0e10cSrcweir if( aProps.getLength() > 0 ) 84*cdf0e10cSrcweir aProps[0] >>= mbBlacklistCurrentDevice; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextureSize" )); 87*cdf0e10cSrcweir aProps = GetProperties( aName ); 88*cdf0e10cSrcweir if( aProps.getLength() > 0 ) 89*cdf0e10cSrcweir maMaxTextureSize.reset( aProps[0].get<sal_Int32>() ); 90*cdf0e10cSrcweir else 91*cdf0e10cSrcweir maMaxTextureSize.reset(); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir catch( uno::Exception& ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir OSL_ENSURE( false, 96*cdf0e10cSrcweir rtl::OUStringToOString( 97*cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 98*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir DXCanvasItem::~DXCanvasItem() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir if( !mbValuesDirty ) 105*cdf0e10cSrcweir return; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir try 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aName(1); 110*cdf0e10cSrcweir aName[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DeviceBlacklist" )); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir uno::Sequence< sal_Int32 > aValues( sizeof(DeviceInfo)/sizeof(sal_Int32)*maValues.size() ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir sal_Int32* pValues = aValues.getArray(); 115*cdf0e10cSrcweir ValueSet::const_iterator aIter( maValues.begin() ); 116*cdf0e10cSrcweir const ValueSet::const_iterator aEnd( maValues.end() ); 117*cdf0e10cSrcweir while( aIter != aEnd ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir const DeviceInfo& rInfo( *aIter ); 120*cdf0e10cSrcweir *pValues++ = rInfo.nVendorId; 121*cdf0e10cSrcweir *pValues++ = rInfo.nDeviceId; 122*cdf0e10cSrcweir *pValues++ = rInfo.nDeviceSubSysId; 123*cdf0e10cSrcweir *pValues++ = rInfo.nDeviceRevision; 124*cdf0e10cSrcweir *pValues++ = rInfo.nDriverId; 125*cdf0e10cSrcweir *pValues++ = rInfo.nDriverVersion; 126*cdf0e10cSrcweir *pValues++ = rInfo.nDriverSubVersion; 127*cdf0e10cSrcweir *pValues++ = rInfo.nDriverBuildId; 128*cdf0e10cSrcweir ++aIter; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir uno::Sequence< uno::Any > aValue(1); 132*cdf0e10cSrcweir aValue[0] <<= aValues; 133*cdf0e10cSrcweir PutProperties( aName, aValue ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir catch( uno::Exception& ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir OSL_ENSURE( false, 138*cdf0e10cSrcweir rtl::OUStringToOString( 139*cdf0e10cSrcweir comphelper::anyToString( cppu::getCaughtException() ), 140*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ).getStr() ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir void DXCanvasItem::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& ) {} 145*cdf0e10cSrcweir void DXCanvasItem::Commit() {} 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir bool DXCanvasItem::isDeviceUsable( const DeviceInfo& rDeviceInfo ) const 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir return maValues.find(rDeviceInfo) == maValues.end(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir bool DXCanvasItem::isBlacklistCurrentDevice() const 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir return mbBlacklistCurrentDevice; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir void DXCanvasItem::blacklistDevice( const DeviceInfo& rDeviceInfo ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir mbValuesDirty = true; 160*cdf0e10cSrcweir maValues.insert(rDeviceInfo); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir void DXCanvasItem::adaptMaxTextureSize( basegfx::B2IVector& io_maxTextureSize ) const 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir if( maMaxTextureSize ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir io_maxTextureSize.setX( 168*cdf0e10cSrcweir std::min( *maMaxTextureSize, 169*cdf0e10cSrcweir io_maxTextureSize.getX() )); 170*cdf0e10cSrcweir io_maxTextureSize.setY( 171*cdf0e10cSrcweir std::min( *maMaxTextureSize, 172*cdf0e10cSrcweir io_maxTextureSize.getY() )); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir } 177