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 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 33 #include <vcl/image.hxx> 34 #include <vcl/virdev.hxx> 35 //#include <toolkit/unoiface.hxx> 36 #include <toolkit/unohlp.hxx> 37 #include <svl/itemprop.hxx> 38 #include <svl/smplhint.hxx> 39 #include <vcl/svapp.hxx> 40 #include <vcl/settings.hxx> 41 #include <com/sun/star/awt/XBitmap.hpp> 42 43 #include "targuno.hxx" 44 #include "miscuno.hxx" 45 #include "docuno.hxx" 46 #include "datauno.hxx" 47 #include "nameuno.hxx" 48 #include "docsh.hxx" 49 #include "content.hxx" 50 #include "unoguard.hxx" 51 #include "scresid.hxx" 52 #include "sc.hrc" 53 #include "unonames.hxx" 54 55 using namespace ::com::sun::star; 56 57 //------------------------------------------------------------------------ 58 59 sal_uInt16 nTypeResIds[SC_LINKTARGETTYPE_COUNT] = 60 { 61 SCSTR_CONTENT_TABLE, // SC_LINKTARGETTYPE_SHEET 62 SCSTR_CONTENT_RANGENAME, // SC_LINKTARGETTYPE_RANGENAME 63 SCSTR_CONTENT_DBAREA // SC_LINKTARGETTYPE_DBAREA 64 }; 65 66 const SfxItemPropertyMapEntry* lcl_GetLinkTargetMap() 67 { 68 static SfxItemPropertyMapEntry aLinkTargetMap_Impl[] = 69 { 70 {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((const uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 }, 71 {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, 72 {0,0,0,0,0,0} 73 }; 74 return aLinkTargetMap_Impl; 75 } 76 77 //------------------------------------------------------------------------ 78 79 // service for ScLinkTargetTypeObj is not defined 80 // must not support document::LinkTarget because the target type cannot be used as a target 81 82 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" ) 83 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj, "ScLinkTargetTypeObj", "com.sun.star.document.LinkTargetSupplier" ) 84 SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj, "ScLinkTargetsObj", "com.sun.star.document.LinkTargets" ) 85 86 //------------------------------------------------------------------------ 87 88 ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell* pDocSh) : 89 pDocShell( pDocSh ) 90 { 91 pDocShell->GetDocument()->AddUnoObject(*this); 92 93 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 94 aNames[i] = String( ScResId( nTypeResIds[i] ) ); 95 } 96 97 ScLinkTargetTypesObj::~ScLinkTargetTypesObj() 98 { 99 if (pDocShell) 100 pDocShell->GetDocument()->RemoveUnoObject(*this); 101 } 102 103 void ScLinkTargetTypesObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 104 { 105 if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 106 pDocShell = NULL; // document gone 107 } 108 109 // container::XNameAccess 110 111 uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const rtl::OUString& aName) 112 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 113 { 114 if (pDocShell) 115 { 116 String aNameStr(aName); 117 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 118 if ( aNames[i] == aNameStr ) 119 return uno::makeAny(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i ))); 120 } 121 122 throw container::NoSuchElementException(); 123 // return uno::Any(); 124 } 125 126 uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames(void) throw( uno::RuntimeException ) 127 { 128 uno::Sequence<rtl::OUString> aRet(SC_LINKTARGETTYPE_COUNT); 129 rtl::OUString* pArray = aRet.getArray(); 130 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 131 pArray[i] = aNames[i]; 132 return aRet; 133 } 134 135 sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException ) 136 { 137 String aNameStr = aName; 138 for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 139 if ( aNames[i] == aNameStr ) 140 return sal_True; 141 return sal_False; 142 } 143 144 // container::XElementAccess 145 146 uno::Type SAL_CALL ScLinkTargetTypesObj::getElementType(void) throw( uno::RuntimeException ) 147 { 148 return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); 149 } 150 151 sal_Bool SAL_CALL ScLinkTargetTypesObj::hasElements(void) throw( uno::RuntimeException ) 152 { 153 return sal_True; 154 } 155 156 //------------------------------------------------------------------------ 157 158 ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell* pDocSh, sal_uInt16 nT) : 159 pDocShell( pDocSh ), 160 nType( nT ) 161 { 162 pDocShell->GetDocument()->AddUnoObject(*this); 163 aName = String( ScResId( nTypeResIds[nType] ) ); //! on demand? 164 } 165 166 ScLinkTargetTypeObj::~ScLinkTargetTypeObj() 167 { 168 if (pDocShell) 169 pDocShell->GetDocument()->RemoveUnoObject(*this); 170 } 171 172 void ScLinkTargetTypeObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 173 { 174 if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 175 pDocShell = NULL; // document gone 176 } 177 178 // document::XLinkTargetSupplier 179 180 uno::Reference< container::XNameAccess > SAL_CALL ScLinkTargetTypeObj::getLinks(void) throw( uno::RuntimeException ) 181 { 182 uno::Reference< container::XNameAccess > xCollection; 183 184 if ( pDocShell ) 185 { 186 switch ( nType ) 187 { 188 case SC_LINKTARGETTYPE_SHEET: 189 xCollection.set(new ScTableSheetsObj(pDocShell)); 190 break; 191 case SC_LINKTARGETTYPE_RANGENAME: 192 xCollection.set(new ScNamedRangesObj(pDocShell)); 193 break; 194 case SC_LINKTARGETTYPE_DBAREA: 195 xCollection.set(new ScDatabaseRangesObj(pDocShell)); 196 break; 197 default: 198 DBG_ERROR("invalid type"); 199 } 200 } 201 202 // wrap collection in ScLinkTargetsObj because service document::LinkTargets requires 203 // beans::XPropertySet as ElementType in container::XNameAccess. 204 if ( xCollection.is() ) 205 return new ScLinkTargetsObj( xCollection ); 206 return NULL; 207 } 208 209 // beans::XPropertySet 210 211 uno::Reference< beans::XPropertySetInfo > SAL_CALL ScLinkTargetTypeObj::getPropertySetInfo(void) throw( uno::RuntimeException ) 212 { 213 ScUnoGuard aGuard; 214 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() )); 215 return aRef; 216 } 217 218 void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const rtl::OUString& /* aPropertyName */, 219 const uno::Any& /* aValue */) 220 throw( beans::UnknownPropertyException, 221 beans::PropertyVetoException, 222 lang::IllegalArgumentException, 223 lang::WrappedTargetException, 224 uno::RuntimeException ) 225 { 226 // everything is read-only 227 //! exception? 228 } 229 230 // static 231 void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any& rRet, sal_uInt16 nType ) 232 { 233 sal_uInt16 nImgId = 0; 234 switch ( nType ) 235 { 236 case SC_LINKTARGETTYPE_SHEET: 237 nImgId = SC_CONTENT_TABLE; 238 break; 239 case SC_LINKTARGETTYPE_RANGENAME: 240 nImgId = SC_CONTENT_RANGENAME; 241 break; 242 case SC_LINKTARGETTYPE_DBAREA: 243 nImgId = SC_CONTENT_DBAREA; 244 break; 245 } 246 if (nImgId) 247 { 248 sal_Bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 249 ImageList aEntryImages( ScResId( bHighContrast ? RID_IMAGELIST_H_NAVCONT : RID_IMAGELIST_NAVCONT ) ); 250 const Image& rImage = aEntryImages.GetImage( nImgId ); 251 rRet <<= uno::Reference< awt::XBitmap > (VCLUnoHelper::CreateBitmap( rImage.GetBitmapEx() )); 252 } 253 } 254 255 uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const rtl::OUString& PropertyName) 256 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 257 { 258 uno::Any aRet; 259 String aNameStr(PropertyName); 260 if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPBIT ) ) 261 SetLinkTargetBitmap( aRet, nType ); 262 else if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPNAME ) ) 263 aRet <<= rtl::OUString( aName ); 264 265 return aRet; 266 } 267 268 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj ) 269 270 //------------------------------------------------------------------------ 271 272 ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference< container::XNameAccess > & rColl ) : 273 xCollection( rColl ) 274 { 275 DBG_ASSERT( xCollection.is(), "ScLinkTargetsObj: NULL" ); 276 } 277 278 ScLinkTargetsObj::~ScLinkTargetsObj() 279 { 280 } 281 282 // container::XNameAccess 283 284 uno::Any SAL_CALL ScLinkTargetsObj::getByName(const rtl::OUString& aName) 285 throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 286 { 287 uno::Reference< beans::XPropertySet > xProp( ScUnoHelpFunctions::AnyToInterface( xCollection->getByName(aName) ), uno::UNO_QUERY ); 288 if (xProp.is()) 289 return uno::makeAny(xProp); 290 291 throw container::NoSuchElementException(); 292 // return uno::Any(); 293 } 294 295 uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetsObj::getElementNames(void) throw( uno::RuntimeException ) 296 { 297 return xCollection->getElementNames(); 298 } 299 300 sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException ) 301 { 302 return xCollection->hasByName(aName); 303 } 304 305 // container::XElementAccess 306 307 uno::Type SAL_CALL ScLinkTargetsObj::getElementType(void) throw( uno::RuntimeException ) 308 { 309 return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); 310 } 311 312 sal_Bool SAL_CALL ScLinkTargetsObj::hasElements(void) throw( uno::RuntimeException ) 313 { 314 return xCollection->hasElements(); 315 } 316 317 318 319