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: imageresourceaccess.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_svtools.hxx"
33 #include "bindablecontrolhelper.hxx"
34 #include <com/sun/star/form/binding/XBindableValue.hpp>
35 #include <com/sun/star/form/binding/XValueBinding.hpp>
36 #include <com/sun/star/form/binding/XListEntrySink.hpp>
37 #include <com/sun/star/form/binding/XListEntrySource.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <com/sun/star/table/CellRangeAddress.hpp>
41 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
42 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <com/sun/star/table/CellAddress.hpp>
45 #include <com/sun/star/beans/NamedValue.hpp>
47 //........................................................................
50 //........................................................................
53 #define C2U(cChar) rtl::OUString::createFromAscii(cChar)
56 using namespace ::com::sun::star
;
58 bool lcl_isNamedRange( const rtl::OUString
& sAddress
, const uno::Reference
< frame::XModel
>& xModel
, table::CellRangeAddress
& aAddress
)
61 const static rtl::OUString
sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
62 uno::Reference
< sheet::XCellRangeReferrer
> xReferrer
;
65 uno::Reference
< beans::XPropertySet
> xPropSet( xModel
, uno::UNO_QUERY_THROW
);
66 uno::Reference
< container::XNameAccess
> xNamed( xPropSet
->getPropertyValue( sNamedRanges
), uno::UNO_QUERY_THROW
);
67 xReferrer
.set ( xNamed
->getByName( sAddress
), uno::UNO_QUERY
);
69 catch( uno::Exception
& /*e*/ )
75 uno::Reference
< sheet::XCellRangeAddressable
> xRangeAddressable( xReferrer
->getReferredCells(), uno::UNO_QUERY
);
76 if ( xRangeAddressable
.is() )
78 aAddress
= xRangeAddressable
->getRangeAddress();
87 BindableControlHelper::ApplyListSourceAndBindableData( const com::sun::star::uno::Reference
< com::sun::star::frame::XModel
>& xModel
, const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>& rObj
, const rtl::OUString
& rsCtrlSource
, const rtl::OUString
& rsRowSource
)
90 uno::Reference
< lang::XMultiServiceFactory
> xFac
;
92 xFac
.set( xModel
, uno::UNO_QUERY
);
93 uno::Reference
< form::binding::XBindableValue
> xBindable( rObj
, uno::UNO_QUERY
);
94 if ( xFac
.is() && rsCtrlSource
.getLength() && xBindable
.is() )
97 // OOo address structures
98 // RefCell - convert from XL
99 // pretend we converted the imported string address into the
100 // appropriate address structure
101 uno::Reference
< beans::XPropertySet
> xConvertor( xFac
->createInstance( C2U( "com.sun.star.table.CellAddressConversion" )), uno::UNO_QUERY
);
102 table::CellAddress aAddress
;
103 if ( xConvertor
.is() )
105 // we need this service to properly convert XL notation also
106 // Should be easy to extend
107 xConvertor
->setPropertyValue( C2U( "XL_A1_Representation" ), uno::makeAny( rsCtrlSource
) );
108 xConvertor
->getPropertyValue( C2U( "Address" ) ) >>= aAddress
;
111 beans::NamedValue aArg1
;
112 aArg1
.Name
= C2U("BoundCell");
113 aArg1
.Value
<<= aAddress
;
115 uno::Sequence
< uno::Any
> aArgs(1);
116 aArgs
[ 0 ] <<= aArg1
;
118 uno::Reference
< form::binding::XValueBinding
> xBinding( xFac
->createInstanceWithArguments( C2U("com.sun.star.table.CellValueBinding" ), aArgs
), uno::UNO_QUERY
);
119 xBindable
->setValueBinding( xBinding
);
121 else if ( xBindable
.is() ) // reset it
122 xBindable
->setValueBinding( uno::Reference
< form::binding::XValueBinding
>() );
123 uno::Reference
< form::binding::XListEntrySink
> xListEntrySink( rObj
, uno::UNO_QUERY
);
124 if ( xFac
.is() && rsRowSource
.getLength() && xListEntrySink
.is() )
127 // OOo address structures
128 // RefCell - convert from XL
129 // pretend we converted the imported string address into the
130 // appropriate address structure
131 uno::Reference
< beans::XPropertySet
> xConvertor( xFac
->createInstance( C2U( "com.sun.star.table.CellRangeAddressConversion" )), uno::UNO_QUERY
);
132 table::CellRangeAddress aAddress
;
133 if ( xConvertor
.is() )
135 if ( !lcl_isNamedRange( rsRowSource
, xModel
, aAddress
) )
137 // we need this service to properly convert XL notation also
138 // Should be easy to extend
139 xConvertor
->setPropertyValue( C2U( "XL_A1_Representation" ), uno::makeAny( rsRowSource
) );
140 xConvertor
->getPropertyValue( C2U( "Address" ) ) >>= aAddress
;
144 beans::NamedValue aArg1
;
145 aArg1
.Name
= C2U("CellRange");
146 aArg1
.Value
<<= aAddress
;
148 uno::Sequence
< uno::Any
> aArgs(1);
149 aArgs
[ 0 ] <<= aArg1
;
151 uno::Reference
< form::binding::XListEntrySource
> xSource( xFac
->createInstanceWithArguments( C2U("com.sun.star.table.CellRangeListSource" ), aArgs
), uno::UNO_QUERY
);
152 xListEntrySink
->setListEntrySource( xSource
);
154 else if ( xListEntrySink
.is() ) // reset
155 xListEntrySink
->setListEntrySource( uno::Reference
< form::binding::XListEntrySource
>() );
159 //........................................................................
161 //........................................................................