1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: targuno.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <vcl/image.hxx>
37 #include <vcl/virdev.hxx>
38 //#include <toolkit/unoiface.hxx>
39 #include <toolkit/unohlp.hxx>
40 #include <svtools/itemprop.hxx>
41 #include <svtools/smplhint.hxx>
42 #include <vcl/svapp.hxx>
43 #include <vcl/settings.hxx>
44 #include <com/sun/star/awt/XBitmap.hpp>
46 #include "targuno.hxx"
47 #include "miscuno.hxx"
49 #include "datauno.hxx"
50 #include "nameuno.hxx"
52 #include "content.hxx"
53 #include "unoguard.hxx"
54 #include "scresid.hxx"
56 #include "unonames.hxx"
58 using namespace ::com::sun::star
;
60 //------------------------------------------------------------------------
62 sal_uInt16 nTypeResIds
[SC_LINKTARGETTYPE_COUNT
] =
64 SCSTR_CONTENT_TABLE
, // SC_LINKTARGETTYPE_SHEET
65 SCSTR_CONTENT_RANGENAME
, // SC_LINKTARGETTYPE_RANGENAME
66 SCSTR_CONTENT_DBAREA
// SC_LINKTARGETTYPE_DBAREA
69 const SfxItemPropertyMap
* lcl_GetLinkTargetMap()
71 static SfxItemPropertyMap aLinkTargetMap_Impl
[] =
73 {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT
), 0, &getCppuType((const uno::Reference
<awt::XBitmap
>*)0), beans::PropertyAttribute::READONLY
, 0 },
74 {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME
), 0, &getCppuType((const ::rtl::OUString
*)0), beans::PropertyAttribute::READONLY
, 0 },
77 return aLinkTargetMap_Impl
;
80 //------------------------------------------------------------------------
82 // service for ScLinkTargetTypeObj is not defined
83 // must not support document::LinkTarget because the target type cannot be used as a target
85 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj
, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
86 SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj
, "ScLinkTargetTypeObj", "com.sun.star.document.LinkTargetSupplier" )
87 SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj
, "ScLinkTargetsObj", "com.sun.star.document.LinkTargets" )
89 //------------------------------------------------------------------------
91 ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell
* pDocSh
) :
94 pDocShell
->GetDocument()->AddUnoObject(*this);
96 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
97 aNames
[i
] = String( ScResId( nTypeResIds
[i
] ) );
100 ScLinkTargetTypesObj::~ScLinkTargetTypesObj()
103 pDocShell
->GetDocument()->RemoveUnoObject(*this);
106 void ScLinkTargetTypesObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
108 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
109 pDocShell
= NULL
; // document gone
112 // container::XNameAccess
114 uno::Any SAL_CALL
ScLinkTargetTypesObj::getByName(const rtl::OUString
& aName
)
115 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
119 String
aNameStr(aName
);
120 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
121 if ( aNames
[i
] == aNameStr
)
122 return uno::makeAny(uno::Reference
< beans::XPropertySet
>(new ScLinkTargetTypeObj( pDocShell
, i
)));
125 throw container::NoSuchElementException();
126 // return uno::Any();
129 uno::Sequence
<rtl::OUString
> SAL_CALL
ScLinkTargetTypesObj::getElementNames(void) throw( uno::RuntimeException
)
131 uno::Sequence
<rtl::OUString
> aRet(SC_LINKTARGETTYPE_COUNT
);
132 rtl::OUString
* pArray
= aRet
.getArray();
133 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
134 pArray
[i
] = aNames
[i
];
138 sal_Bool SAL_CALL
ScLinkTargetTypesObj::hasByName(const rtl::OUString
& aName
) throw( uno::RuntimeException
)
140 String aNameStr
= aName
;
141 for (sal_uInt16 i
=0; i
<SC_LINKTARGETTYPE_COUNT
; i
++)
142 if ( aNames
[i
] == aNameStr
)
147 // container::XElementAccess
149 uno::Type SAL_CALL
ScLinkTargetTypesObj::getElementType(void) throw( uno::RuntimeException
)
151 return ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
154 sal_Bool SAL_CALL
ScLinkTargetTypesObj::hasElements(void) throw( uno::RuntimeException
)
159 //------------------------------------------------------------------------
161 ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell
* pDocSh
, sal_uInt16 nT
) :
165 pDocShell
->GetDocument()->AddUnoObject(*this);
166 aName
= String( ScResId( nTypeResIds
[nType
] ) ); //! on demand?
169 ScLinkTargetTypeObj::~ScLinkTargetTypeObj()
172 pDocShell
->GetDocument()->RemoveUnoObject(*this);
175 void ScLinkTargetTypeObj::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
177 if ( rHint
.ISA( SfxSimpleHint
) && ((const SfxSimpleHint
&)rHint
).GetId() == SFX_HINT_DYING
)
178 pDocShell
= NULL
; // document gone
181 // document::XLinkTargetSupplier
183 uno::Reference
< container::XNameAccess
> SAL_CALL
ScLinkTargetTypeObj::getLinks(void) throw( uno::RuntimeException
)
185 uno::Reference
< container::XNameAccess
> xCollection
;
191 case SC_LINKTARGETTYPE_SHEET
:
192 xCollection
.set(new ScTableSheetsObj(pDocShell
));
194 case SC_LINKTARGETTYPE_RANGENAME
:
195 xCollection
.set(new ScNamedRangesObj(pDocShell
));
197 case SC_LINKTARGETTYPE_DBAREA
:
198 xCollection
.set(new ScDatabaseRangesObj(pDocShell
));
201 DBG_ERROR("invalid type");
205 // wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
206 // beans::XPropertySet as ElementType in container::XNameAccess.
207 if ( xCollection
.is() )
208 return new ScLinkTargetsObj( xCollection
);
212 // beans::XPropertySet
214 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ScLinkTargetTypeObj::getPropertySetInfo(void) throw( uno::RuntimeException
)
217 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
221 void SAL_CALL
ScLinkTargetTypeObj::setPropertyValue(const rtl::OUString
& /* aPropertyName */,
222 const uno::Any
& /* aValue */)
223 throw( beans::UnknownPropertyException
,
224 beans::PropertyVetoException
,
225 lang::IllegalArgumentException
,
226 lang::WrappedTargetException
,
227 uno::RuntimeException
)
229 // everything is read-only
234 void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any
& rRet
, sal_uInt16 nType
)
236 sal_uInt16 nImgId
= 0;
239 case SC_LINKTARGETTYPE_SHEET
:
240 nImgId
= SC_CONTENT_TABLE
;
242 case SC_LINKTARGETTYPE_RANGENAME
:
243 nImgId
= SC_CONTENT_RANGENAME
;
245 case SC_LINKTARGETTYPE_DBAREA
:
246 nImgId
= SC_CONTENT_DBAREA
;
251 BOOL bHighContrast
= Application::GetSettings().GetStyleSettings().GetWindowColor().IsDark();
252 ImageList
aEntryImages( ScResId( bHighContrast
? RID_IMAGELIST_H_NAVCONT
: RID_IMAGELIST_NAVCONT
) );
253 const Image
& rImage
= aEntryImages
.GetImage( nImgId
);
254 rRet
<<= uno::Reference
< awt::XBitmap
> (VCLUnoHelper::CreateBitmap( rImage
.GetBitmapEx() ));
258 uno::Any SAL_CALL
ScLinkTargetTypeObj::getPropertyValue(const rtl::OUString
& PropertyName
)
259 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
262 String
aNameStr(PropertyName
);
263 if ( aNameStr
.EqualsAscii( SC_UNO_LINKDISPBIT
) )
264 SetLinkTargetBitmap( aRet
, nType
);
265 else if ( aNameStr
.EqualsAscii( SC_UNO_LINKDISPNAME
) )
266 aRet
<<= rtl::OUString( aName
);
271 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj
)
273 //------------------------------------------------------------------------
275 ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference
< container::XNameAccess
> & rColl
) :
278 DBG_ASSERT( xCollection
.is(), "ScLinkTargetsObj: NULL" );
281 ScLinkTargetsObj::~ScLinkTargetsObj()
285 // container::XNameAccess
287 uno::Any SAL_CALL
ScLinkTargetsObj::getByName(const rtl::OUString
& aName
)
288 throw( container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
290 uno::Reference
< beans::XPropertySet
> xProp( ScUnoHelpFunctions::AnyToInterface( xCollection
->getByName(aName
) ), uno::UNO_QUERY
);
292 return uno::makeAny(xProp
);
294 throw container::NoSuchElementException();
295 // return uno::Any();
298 uno::Sequence
<rtl::OUString
> SAL_CALL
ScLinkTargetsObj::getElementNames(void) throw( uno::RuntimeException
)
300 return xCollection
->getElementNames();
303 sal_Bool SAL_CALL
ScLinkTargetsObj::hasByName(const rtl::OUString
& aName
) throw( uno::RuntimeException
)
305 return xCollection
->hasByName(aName
);
308 // container::XElementAccess
310 uno::Type SAL_CALL
ScLinkTargetsObj::getElementType(void) throw( uno::RuntimeException
)
312 return ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
315 sal_Bool SAL_CALL
ScLinkTargetsObj::hasElements(void) throw( uno::RuntimeException
)
317 return xCollection
->hasElements();