1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * This file is part of OpenOffice.org. 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 12*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 19*cdf0e10cSrcweir * 20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 21*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 23*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 24*cdf0e10cSrcweir * 25*cdf0e10cSrcweir ************************************************************************/ 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_extensions.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "propertyhandler.hxx" 31*cdf0e10cSrcweir #include "formmetadata.hxx" 32*cdf0e10cSrcweir #include "formstrings.hxx" 33*cdf0e10cSrcweir #include "handlerhelper.hxx" 34*cdf0e10cSrcweir #include "cellbindinghelper.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** === begin UNO includes === **/ 37*cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/drawing/XControlShape.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/container/XMap.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/inspection/XNumericControl.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/util/MeasureUnit.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheet.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/table/XColumnRowRange.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp> 50*cdf0e10cSrcweir /** === end UNO includes === **/ 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 53*cdf0e10cSrcweir #include <comphelper/componentbase.hxx> 54*cdf0e10cSrcweir #include <tools/debug.hxx> 55*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //........................................................................ 58*cdf0e10cSrcweir namespace pcr 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir //........................................................................ 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** === begin UNO using === **/ 63*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 64*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 65*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 66*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 67*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 68*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 69*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 70*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 71*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 72*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 73*cdf0e10cSrcweir using ::com::sun::star::uno::Type; 74*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext; 75*cdf0e10cSrcweir using ::com::sun::star::beans::UnknownPropertyException; 76*cdf0e10cSrcweir using ::com::sun::star::beans::Property; 77*cdf0e10cSrcweir using ::com::sun::star::awt::XControlModel; 78*cdf0e10cSrcweir using ::com::sun::star::drawing::XControlShape; 79*cdf0e10cSrcweir using ::com::sun::star::container::XMap; 80*cdf0e10cSrcweir using ::com::sun::star::inspection::LineDescriptor; 81*cdf0e10cSrcweir using ::com::sun::star::inspection::XPropertyControlFactory; 82*cdf0e10cSrcweir using ::com::sun::star::lang::NullPointerException; 83*cdf0e10cSrcweir using ::com::sun::star::beans::Optional; 84*cdf0e10cSrcweir using ::com::sun::star::inspection::XNumericControl; 85*cdf0e10cSrcweir using ::com::sun::star::drawing::XShape; 86*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyChangeEvent; 87*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 88*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 89*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertyChangeListener; 90*cdf0e10cSrcweir using ::com::sun::star::text::TextContentAnchorType; 91*cdf0e10cSrcweir using ::com::sun::star::text::TextContentAnchorType_AT_PARAGRAPH; 92*cdf0e10cSrcweir using ::com::sun::star::text::TextContentAnchorType_AS_CHARACTER; 93*cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySetInfo; 94*cdf0e10cSrcweir using ::com::sun::star::inspection::XObjectInspectorUI; 95*cdf0e10cSrcweir using ::com::sun::star::lang::XServiceInfo; 96*cdf0e10cSrcweir using ::com::sun::star::sheet::XSpreadsheet; 97*cdf0e10cSrcweir using ::com::sun::star::table::XColumnRowRange; 98*cdf0e10cSrcweir using ::com::sun::star::table::XTableColumns; 99*cdf0e10cSrcweir using ::com::sun::star::table::XTableRows; 100*cdf0e10cSrcweir using ::com::sun::star::table::XCellRange; 101*cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess; 102*cdf0e10cSrcweir using ::com::sun::star::container::XChild; 103*cdf0e10cSrcweir using ::com::sun::star::form::XGridColumnFactory; 104*cdf0e10cSrcweir /** === end UNO using === **/ 105*cdf0e10cSrcweir namespace MeasureUnit = ::com::sun::star::util::MeasureUnit; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir typedef ::com::sun::star::awt::Point AwtPoint; 108*cdf0e10cSrcweir typedef ::com::sun::star::awt::Size AwtSize; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir #define ANCHOR_TO_SHEET 0 111*cdf0e10cSrcweir #define ANCHOR_TO_CELL 1 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir //==================================================================== 114*cdf0e10cSrcweir //= BroadcastHelperBase 115*cdf0e10cSrcweir //==================================================================== 116*cdf0e10cSrcweir class BroadcastHelperBase 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir protected: 119*cdf0e10cSrcweir BroadcastHelperBase( ::osl::Mutex& _rMutex ) 120*cdf0e10cSrcweir :maBHelper( _rMutex ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir protected: 125*cdf0e10cSrcweir ::cppu::OBroadcastHelper& getBroadcastHelper() { return maBHelper; } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir private: 128*cdf0e10cSrcweir ::cppu::OBroadcastHelper maBHelper; 129*cdf0e10cSrcweir }; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir //==================================================================== 132*cdf0e10cSrcweir //= ShapeGeometryChangeNotifier - declaration 133*cdf0e10cSrcweir //==================================================================== 134*cdf0e10cSrcweir /** helper class to work around the ...unfortunate implementation of property change broadcasts 135*cdf0e10cSrcweir in the XShape implementation, which broadcasts way too generous and unspecified 136*cdf0e10cSrcweir */ 137*cdf0e10cSrcweir typedef ::comphelper::ComponentBase ShapeGeometryChangeNotifier_CBase; 138*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1 < ::com::sun::star::beans::XPropertyChangeListener 139*cdf0e10cSrcweir > ShapeGeometryChangeNotifier_IBase; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir class ShapeGeometryChangeNotifier :public BroadcastHelperBase 142*cdf0e10cSrcweir ,public ShapeGeometryChangeNotifier_CBase 143*cdf0e10cSrcweir ,public ShapeGeometryChangeNotifier_IBase 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir public: 146*cdf0e10cSrcweir ShapeGeometryChangeNotifier( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rParentMutex, const Reference< XShape >& _shape ) 147*cdf0e10cSrcweir :BroadcastHelperBase( _rParentMutex ) 148*cdf0e10cSrcweir ,ShapeGeometryChangeNotifier_CBase( BroadcastHelperBase::getBroadcastHelper(), ::comphelper::ComponentBase::NoInitializationNeeded() ) 149*cdf0e10cSrcweir ,ShapeGeometryChangeNotifier_IBase() 150*cdf0e10cSrcweir ,m_rParent( _rParent ) 151*cdf0e10cSrcweir ,m_aPropertyChangeListeners( _rParentMutex ) 152*cdf0e10cSrcweir ,m_xShape( _shape ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir ENSURE_OR_THROW( m_xShape.is(), "illegal shape!" ); 155*cdf0e10cSrcweir impl_init_nothrow(); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // property change broadcasting 159*cdf0e10cSrcweir void addPropertyChangeListener( const Reference< XPropertyChangeListener >& _listener ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir m_aPropertyChangeListeners.addInterface( _listener ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir void removePropertyChangeListener( const Reference< XPropertyChangeListener >& _listener ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir m_aPropertyChangeListeners.removeInterface( _listener ); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // XComponent equivalent 169*cdf0e10cSrcweir void dispose() 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir ::osl::MutexGuard aGuard( getMutex() ); 172*cdf0e10cSrcweir impl_dispose_nothrow(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // XInterface 176*cdf0e10cSrcweir virtual void SAL_CALL acquire( ) throw () 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir m_rParent.acquire(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir virtual void SAL_CALL release( ) throw () 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir m_rParent.release(); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir // XPropertyChangeListener 187*cdf0e10cSrcweir virtual void SAL_CALL propertyChange( const PropertyChangeEvent& _event ) throw (RuntimeException); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // XEventListener 190*cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& _event ) throw (RuntimeException); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir protected: 193*cdf0e10cSrcweir virtual ~ShapeGeometryChangeNotifier() 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir if ( !getBroadcastHelper().bDisposed ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir acquire(); 198*cdf0e10cSrcweir dispose(); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir protected: 203*cdf0e10cSrcweir ::cppu::OBroadcastHelper& getBroadcastHelper() { return BroadcastHelperBase::getBroadcastHelper(); } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir private: 206*cdf0e10cSrcweir void impl_init_nothrow(); 207*cdf0e10cSrcweir void impl_dispose_nothrow(); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir private: 210*cdf0e10cSrcweir ::cppu::OWeakObject& m_rParent; 211*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper m_aPropertyChangeListeners; 212*cdf0e10cSrcweir Reference< XShape > m_xShape; 213*cdf0e10cSrcweir }; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir //==================================================================== 216*cdf0e10cSrcweir //= FormGeometryHandler - declaration 217*cdf0e10cSrcweir //==================================================================== 218*cdf0e10cSrcweir class FormGeometryHandler; 219*cdf0e10cSrcweir typedef HandlerComponentBase< FormGeometryHandler > FormGeometryHandler_Base; 220*cdf0e10cSrcweir /** a property handler for any virtual string properties 221*cdf0e10cSrcweir */ 222*cdf0e10cSrcweir class FormGeometryHandler : public FormGeometryHandler_Base 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir public: 225*cdf0e10cSrcweir FormGeometryHandler( 226*cdf0e10cSrcweir const Reference< XComponentContext >& _rxContext 227*cdf0e10cSrcweir ); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static( ) throw (RuntimeException); 230*cdf0e10cSrcweir static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static( ) throw (RuntimeException); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir protected: 233*cdf0e10cSrcweir ~FormGeometryHandler(); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir protected: 236*cdf0e10cSrcweir // XPropertyHandler overriables 237*cdf0e10cSrcweir virtual Any SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException); 238*cdf0e10cSrcweir virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException); 239*cdf0e10cSrcweir virtual LineDescriptor SAL_CALL describePropertyLine( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException); 240*cdf0e10cSrcweir virtual void SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException); 241*cdf0e10cSrcweir virtual void SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException); 242*cdf0e10cSrcweir virtual Sequence< ::rtl::OUString > SAL_CALL getActuatingProperties( ) throw (RuntimeException); 243*cdf0e10cSrcweir virtual void SAL_CALL actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& _rOldValue, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit ) throw (NullPointerException, RuntimeException); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // OComponentHandler overridables 246*cdf0e10cSrcweir virtual void SAL_CALL disposing(); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // PropertyHandler overridables 249*cdf0e10cSrcweir virtual Sequence< Property > SAL_CALL doDescribeSupportedProperties() const; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir protected: 252*cdf0e10cSrcweir virtual void onNewComponent(); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir private: 255*cdf0e10cSrcweir bool impl_haveTextAnchorType_nothrow() const; 256*cdf0e10cSrcweir bool impl_haveSheetAnchorType_nothrow() const; 257*cdf0e10cSrcweir void impl_setSheetAnchorType_nothrow( const sal_Int32 _nAnchorType ) const; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir private: 260*cdf0e10cSrcweir Reference< XControlShape > m_xAssociatedShape; 261*cdf0e10cSrcweir Reference< XPropertySet > m_xShapeProperties; 262*cdf0e10cSrcweir ::rtl::Reference< ShapeGeometryChangeNotifier > m_xChangeNotifier; 263*cdf0e10cSrcweir }; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //==================================================================== 266*cdf0e10cSrcweir //= FormGeometryHandler - implementation 267*cdf0e10cSrcweir //==================================================================== 268*cdf0e10cSrcweir DBG_NAME( FormGeometryHandler ) 269*cdf0e10cSrcweir //-------------------------------------------------------------------- 270*cdf0e10cSrcweir FormGeometryHandler::FormGeometryHandler( const Reference< XComponentContext >& _rxContext ) 271*cdf0e10cSrcweir :FormGeometryHandler_Base( _rxContext ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir DBG_CTOR( FormGeometryHandler, NULL ); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir //-------------------------------------------------------------------- 277*cdf0e10cSrcweir FormGeometryHandler::~FormGeometryHandler( ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir if ( !rBHelper.bDisposed ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir acquire(); 282*cdf0e10cSrcweir dispose(); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir DBG_DTOR( FormGeometryHandler, NULL ); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir //-------------------------------------------------------------------- 289*cdf0e10cSrcweir void FormGeometryHandler::onNewComponent() 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir if ( m_xChangeNotifier.is() ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir m_xChangeNotifier->dispose(); 294*cdf0e10cSrcweir m_xChangeNotifier.clear(); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir m_xAssociatedShape.clear(); 297*cdf0e10cSrcweir m_xShapeProperties.clear(); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir FormGeometryHandler_Base::onNewComponent(); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir try 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir Reference< XControlModel > xControlModel( m_xComponent, UNO_QUERY ); 304*cdf0e10cSrcweir if ( xControlModel.is() ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir // do not ask the map for shapes for grid control columns .... 307*cdf0e10cSrcweir Reference< XChild > xCompChild( m_xComponent, UNO_QUERY_THROW ); 308*cdf0e10cSrcweir Reference< XGridColumnFactory > xCheckGrid( xCompChild->getParent(), UNO_QUERY ); 309*cdf0e10cSrcweir if ( !xCheckGrid.is() ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir Reference< XMap > xControlMap( m_aContext.getContextValueByAsciiName( "ControlShapeAccess" ), UNO_QUERY_THROW ); 312*cdf0e10cSrcweir m_xAssociatedShape.set( xControlMap->get( makeAny( xControlModel ) ), UNO_QUERY_THROW ); 313*cdf0e10cSrcweir m_xShapeProperties.set( m_xAssociatedShape, UNO_QUERY_THROW ); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir catch( const Exception& ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir if ( m_xAssociatedShape.is() ) 323*cdf0e10cSrcweir m_xChangeNotifier = new ShapeGeometryChangeNotifier( *this, m_aMutex, m_xAssociatedShape.get() ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir //-------------------------------------------------------------------- 327*cdf0e10cSrcweir ::rtl::OUString SAL_CALL FormGeometryHandler::getImplementationName_static( ) throw (RuntimeException) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.FormGeometryHandler" ) ); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir //-------------------------------------------------------------------- 333*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL FormGeometryHandler::getSupportedServiceNames_static( ) throw (RuntimeException) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported( 1 ); 336*cdf0e10cSrcweir aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.FormGeometryHandler" ) ); 337*cdf0e10cSrcweir return aSupported; 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir //-------------------------------------------------------------------- 341*cdf0e10cSrcweir Any SAL_CALL FormGeometryHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 344*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir ENSURE_OR_THROW2( m_xAssociatedShape.is(), "internal error: properties, but no shape!", *this ); 347*cdf0e10cSrcweir ENSURE_OR_THROW2( m_xShapeProperties.is(), "internal error: no shape properties!", *this ); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir Any aReturn; 350*cdf0e10cSrcweir try 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir switch ( nPropId ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir case PROPERTY_ID_POSITIONX: 355*cdf0e10cSrcweir aReturn <<= m_xAssociatedShape->getPosition().X; 356*cdf0e10cSrcweir break; 357*cdf0e10cSrcweir case PROPERTY_ID_POSITIONY: 358*cdf0e10cSrcweir aReturn <<= m_xAssociatedShape->getPosition().Y; 359*cdf0e10cSrcweir break; 360*cdf0e10cSrcweir case PROPERTY_ID_WIDTH: 361*cdf0e10cSrcweir aReturn <<= m_xAssociatedShape->getSize().Width; 362*cdf0e10cSrcweir break; 363*cdf0e10cSrcweir case PROPERTY_ID_HEIGHT: 364*cdf0e10cSrcweir aReturn <<= m_xAssociatedShape->getSize().Height; 365*cdf0e10cSrcweir break; 366*cdf0e10cSrcweir case PROPERTY_ID_TEXT_ANCHOR_TYPE: 367*cdf0e10cSrcweir aReturn = m_xShapeProperties->getPropertyValue( PROPERTY_ANCHOR_TYPE ); 368*cdf0e10cSrcweir OSL_ENSURE( aReturn.hasValue(), "FormGeometryHandler::getPropertyValue: illegal anchor type!" ); 369*cdf0e10cSrcweir break; 370*cdf0e10cSrcweir case PROPERTY_ID_SHEET_ANCHOR_TYPE: 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir Reference< XSpreadsheet > xAnchorSheet( m_xShapeProperties->getPropertyValue( PROPERTY_ANCHOR ), UNO_QUERY ); 373*cdf0e10cSrcweir aReturn <<= sal_Int32( xAnchorSheet.is() ? ANCHOR_TO_SHEET : ANCHOR_TO_CELL ); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir break; 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir default: 378*cdf0e10cSrcweir OSL_ENSURE( false, "FormGeometryHandler::getPropertyValue: huh?" ); 379*cdf0e10cSrcweir break; 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir catch( const Exception& ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir return aReturn; 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir //-------------------------------------------------------------------- 390*cdf0e10cSrcweir void SAL_CALL FormGeometryHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 393*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir ENSURE_OR_THROW2( m_xAssociatedShape.is(), "internal error: properties, but no shape!", *this ); 396*cdf0e10cSrcweir ENSURE_OR_THROW2( m_xShapeProperties.is(), "internal error: properties, but no shape!", *this ); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir try 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir switch ( nPropId ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir case PROPERTY_ID_POSITIONX: 403*cdf0e10cSrcweir case PROPERTY_ID_POSITIONY: 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir sal_Int32 nPosition(0); 406*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= nPosition ); 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir AwtPoint aPos( m_xAssociatedShape->getPosition() ); 409*cdf0e10cSrcweir if ( nPropId == PROPERTY_ID_POSITIONX ) 410*cdf0e10cSrcweir aPos.X = nPosition; 411*cdf0e10cSrcweir else 412*cdf0e10cSrcweir aPos.Y = nPosition; 413*cdf0e10cSrcweir m_xAssociatedShape->setPosition( aPos ); 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir break; 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir case PROPERTY_ID_WIDTH: 418*cdf0e10cSrcweir case PROPERTY_ID_HEIGHT: 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir sal_Int32 nSize(0); 421*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= nSize ); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir AwtSize aSize( m_xAssociatedShape->getSize() ); 424*cdf0e10cSrcweir if ( nPropId == PROPERTY_ID_WIDTH ) 425*cdf0e10cSrcweir aSize.Width = nSize; 426*cdf0e10cSrcweir else 427*cdf0e10cSrcweir aSize.Height = nSize; 428*cdf0e10cSrcweir m_xAssociatedShape->setSize( aSize ); 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir break; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir case PROPERTY_ID_TEXT_ANCHOR_TYPE: 433*cdf0e10cSrcweir m_xShapeProperties->setPropertyValue( PROPERTY_ANCHOR_TYPE, _rValue ); 434*cdf0e10cSrcweir break; 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir case PROPERTY_ID_SHEET_ANCHOR_TYPE: 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir sal_Int32 nSheetAnchorType = 0; 439*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= nSheetAnchorType ); 440*cdf0e10cSrcweir impl_setSheetAnchorType_nothrow( nSheetAnchorType ); 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir break; 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir default: 445*cdf0e10cSrcweir OSL_ENSURE( false, "FormGeometryHandler::getPropertyValue: huh?" ); 446*cdf0e10cSrcweir break; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir catch( const Exception& ) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir //-------------------------------------------------------------------- 456*cdf0e10cSrcweir LineDescriptor SAL_CALL FormGeometryHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, 457*cdf0e10cSrcweir const Reference< XPropertyControlFactory >& _rxControlFactory ) 458*cdf0e10cSrcweir throw (UnknownPropertyException, NullPointerException, RuntimeException) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 461*cdf0e10cSrcweir PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) ); 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir LineDescriptor aLineDesc( PropertyHandler::describePropertyLine( _rPropertyName, _rxControlFactory ) ); 464*cdf0e10cSrcweir try 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir bool bIsSize = false; 467*cdf0e10cSrcweir switch ( nPropId ) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir case PROPERTY_ID_WIDTH: 470*cdf0e10cSrcweir case PROPERTY_ID_HEIGHT: 471*cdf0e10cSrcweir bIsSize = true; 472*cdf0e10cSrcweir // NO break! 473*cdf0e10cSrcweir case PROPERTY_ID_POSITIONX: 474*cdf0e10cSrcweir case PROPERTY_ID_POSITIONY: 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir Optional< double > aZero( sal_True, 0 ); 477*cdf0e10cSrcweir Optional< double > aValueNotPresent( sal_False, 0 ); 478*cdf0e10cSrcweir aLineDesc.Control = PropertyHandlerHelper::createNumericControl( 479*cdf0e10cSrcweir _rxControlFactory, 2, bIsSize ? aZero : aValueNotPresent, aValueNotPresent, sal_False ); 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir Reference< XNumericControl > xNumericControl( aLineDesc.Control, UNO_QUERY_THROW ); 482*cdf0e10cSrcweir xNumericControl->setValueUnit( MeasureUnit::MM_100TH ); 483*cdf0e10cSrcweir xNumericControl->setDisplayUnit( impl_getDocumentMeasurementUnit_throw() ); 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir break; 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir case PROPERTY_ID_TEXT_ANCHOR_TYPE: 488*cdf0e10cSrcweir case PROPERTY_ID_SHEET_ANCHOR_TYPE: 489*cdf0e10cSrcweir // default handling from PropertyHandler is sufficient 490*cdf0e10cSrcweir break; 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir default: 493*cdf0e10cSrcweir OSL_ENSURE( false, "FormGeometryHandler::describePropertyLine: huh?" ); 494*cdf0e10cSrcweir break; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir catch( const Exception& ) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir return aLineDesc; 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir //-------------------------------------------------------------------- 505*cdf0e10cSrcweir void SAL_CALL FormGeometryHandler::addPropertyChangeListener( const Reference< XPropertyChangeListener >& _listener ) throw (RuntimeException) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 508*cdf0e10cSrcweir OSL_PRECOND( m_xChangeNotifier.is(), "FormGeometryHandler::addPropertyChangeListener: no notified, implies no shape!?" ); 509*cdf0e10cSrcweir if ( m_xChangeNotifier.is() ) 510*cdf0e10cSrcweir m_xChangeNotifier->addPropertyChangeListener( _listener ); 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir //-------------------------------------------------------------------- 514*cdf0e10cSrcweir void SAL_CALL FormGeometryHandler::removePropertyChangeListener( const Reference< XPropertyChangeListener >& _listener ) throw (RuntimeException) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 517*cdf0e10cSrcweir OSL_PRECOND( m_xChangeNotifier.is(), "FormGeometryHandler::removePropertyChangeListener: no notified, implies no shape!?" ); 518*cdf0e10cSrcweir if ( m_xChangeNotifier.is() ) 519*cdf0e10cSrcweir m_xChangeNotifier->removePropertyChangeListener( _listener ); 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir //-------------------------------------------------------------------- 523*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL FormGeometryHandler::getActuatingProperties( ) throw (RuntimeException) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir Sequence< ::rtl::OUString > aInterestedIn(1); 526*cdf0e10cSrcweir aInterestedIn[0] = PROPERTY_TEXT_ANCHOR_TYPE; 527*cdf0e10cSrcweir return aInterestedIn; 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir //-------------------------------------------------------------------- 531*cdf0e10cSrcweir void SAL_CALL FormGeometryHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir if ( !_rxInspectorUI.is() ) 534*cdf0e10cSrcweir throw NullPointerException(); 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 537*cdf0e10cSrcweir PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) ); 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir switch ( nActuatingPropId ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir case PROPERTY_ID_TEXT_ANCHOR_TYPE: 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir TextContentAnchorType eAnchorType( TextContentAnchorType_AT_PARAGRAPH ); 544*cdf0e10cSrcweir OSL_VERIFY( _rNewValue >>= eAnchorType ); 545*cdf0e10cSrcweir _rxInspectorUI->enablePropertyUI( PROPERTY_POSITIONX, eAnchorType != TextContentAnchorType_AS_CHARACTER ); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir break; 548*cdf0e10cSrcweir default: 549*cdf0e10cSrcweir OSL_ENSURE( false, "FormGeometryHandler::actuatingPropertyChanged: not registered for this property!" ); 550*cdf0e10cSrcweir break; 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir //-------------------------------------------------------------------- 555*cdf0e10cSrcweir Sequence< Property > SAL_CALL FormGeometryHandler::doDescribeSupportedProperties() const 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir if ( !m_xAssociatedShape.is() ) 558*cdf0e10cSrcweir return Sequence< Property >(); 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir ::std::vector< Property > aProperties; 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_POSITIONX ); 563*cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_POSITIONY ); 564*cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_WIDTH ); 565*cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_HEIGHT ); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir if ( impl_haveTextAnchorType_nothrow() ) 568*cdf0e10cSrcweir implAddPropertyDescription( aProperties, PROPERTY_TEXT_ANCHOR_TYPE, ::cppu::UnoType< TextContentAnchorType >::get() ); 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir if ( impl_haveSheetAnchorType_nothrow() ) 571*cdf0e10cSrcweir addInt32PropertyDescription( aProperties, PROPERTY_SHEET_ANCHOR_TYPE ); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir return Sequence< Property >( &(*aProperties.begin()), aProperties.size() ); 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir //-------------------------------------------------------------------- 577*cdf0e10cSrcweir void SAL_CALL FormGeometryHandler::disposing() 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir FormGeometryHandler_Base::disposing(); 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir if ( m_xChangeNotifier.is() ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir m_xChangeNotifier->dispose(); 584*cdf0e10cSrcweir m_xChangeNotifier.clear(); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir //-------------------------------------------------------------------- 589*cdf0e10cSrcweir bool FormGeometryHandler::impl_haveTextAnchorType_nothrow() const 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir ENSURE_OR_THROW( m_xShapeProperties.is(), "not to be called without shape properties" ); 592*cdf0e10cSrcweir try 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI( m_xShapeProperties->getPropertySetInfo(), UNO_SET_THROW ); 595*cdf0e10cSrcweir if ( xPSI->hasPropertyByName( PROPERTY_ANCHOR_TYPE ) ) 596*cdf0e10cSrcweir return true; 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir catch( const Exception& ) 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir return false; 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir //-------------------------------------------------------------------- 606*cdf0e10cSrcweir bool FormGeometryHandler::impl_haveSheetAnchorType_nothrow() const 607*cdf0e10cSrcweir { 608*cdf0e10cSrcweir ENSURE_OR_THROW( m_xShapeProperties.is(), "not to be called without shape properties" ); 609*cdf0e10cSrcweir try 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI( m_xShapeProperties->getPropertySetInfo(), UNO_SET_THROW ); 612*cdf0e10cSrcweir if ( !xPSI->hasPropertyByName( PROPERTY_ANCHOR ) ) 613*cdf0e10cSrcweir return false; 614*cdf0e10cSrcweir Reference< XServiceInfo > xSI( m_xAssociatedShape, UNO_QUERY_THROW ); 615*cdf0e10cSrcweir if ( xSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.Shape" ) ) ) ) 616*cdf0e10cSrcweir return true; 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir catch( const Exception& ) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 621*cdf0e10cSrcweir } 622*cdf0e10cSrcweir return false; 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir //-------------------------------------------------------------------- 626*cdf0e10cSrcweir namespace 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir static sal_Int32 lcl_getLowerBoundRowOrColumn( const Reference< XIndexAccess >& _rxRowsOrColumns, const bool _bRows, 629*cdf0e10cSrcweir const AwtPoint& _rRelativePosition ) 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir sal_Int32 nAccumulated = 0; 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir const sal_Int32& rRelativePos = _bRows ? _rRelativePosition.Y : _rRelativePosition.X; 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir sal_Int32 nElements = _rxRowsOrColumns->getCount(); 636*cdf0e10cSrcweir sal_Int32 currentPos = 0; 637*cdf0e10cSrcweir for ( currentPos=0; currentPos<nElements; ++currentPos ) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir Reference< XPropertySet > xRowOrColumn( _rxRowsOrColumns->getByIndex( currentPos ), UNO_QUERY_THROW ); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir sal_Bool bIsVisible = sal_True; 642*cdf0e10cSrcweir OSL_VERIFY( xRowOrColumn->getPropertyValue( PROPERTY_IS_VISIBLE ) >>= bIsVisible ); 643*cdf0e10cSrcweir if ( !bIsVisible ) 644*cdf0e10cSrcweir continue; 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir sal_Int32 nHeightOrWidth( 0 ); 647*cdf0e10cSrcweir OSL_VERIFY( xRowOrColumn->getPropertyValue( _bRows ? PROPERTY_HEIGHT : PROPERTY_WIDTH ) >>= nHeightOrWidth ); 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir if ( nAccumulated + nHeightOrWidth > rRelativePos ) 650*cdf0e10cSrcweir break; 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir nAccumulated += nHeightOrWidth; 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir return currentPos; 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir //-------------------------------------------------------------------- 660*cdf0e10cSrcweir void FormGeometryHandler::impl_setSheetAnchorType_nothrow( const sal_Int32 _nAnchorType ) const 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir ENSURE_OR_THROW( m_xShapeProperties.is(), "illegal to be called without shape properties." ); 663*cdf0e10cSrcweir try 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir CellBindingHelper aHelper( m_xComponent, impl_getContextDocument_nothrow() ); 666*cdf0e10cSrcweir // find the sheet which the control belongs to 667*cdf0e10cSrcweir Reference< XSpreadsheet > xSheet; 668*cdf0e10cSrcweir aHelper.getControlSheetIndex( xSheet ); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir switch ( _nAnchorType ) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir case ANCHOR_TO_SHEET: 673*cdf0e10cSrcweir OSL_ENSURE( xSheet.is(), 674*cdf0e10cSrcweir "FormGeometryHandler::impl_setSheetAnchorType_nothrow: sheet not found!" ); 675*cdf0e10cSrcweir if ( xSheet.is() ) 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir AwtPoint aPreservePosition( m_xAssociatedShape->getPosition() ); 678*cdf0e10cSrcweir m_xShapeProperties->setPropertyValue( PROPERTY_ANCHOR, makeAny( xSheet ) ); 679*cdf0e10cSrcweir m_xAssociatedShape->setPosition( aPreservePosition ); 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir break; 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir case ANCHOR_TO_CELL: 684*cdf0e10cSrcweir { 685*cdf0e10cSrcweir Reference< XColumnRowRange > xColsRows( xSheet, UNO_QUERY_THROW ); 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir // get the current anchor 688*cdf0e10cSrcweir Reference< XSpreadsheet > xCurrentAnchor; 689*cdf0e10cSrcweir OSL_VERIFY( m_xShapeProperties->getPropertyValue( PROPERTY_ANCHOR ) >>= xCurrentAnchor ); 690*cdf0e10cSrcweir OSL_ENSURE( xCurrentAnchor.is(), "FormGeometryHandler::impl_setSheetAnchorType_nothrow: only to be called when currently anchored to a sheet!" ); 691*cdf0e10cSrcweir 692*cdf0e10cSrcweir // get the current position 693*cdf0e10cSrcweir AwtPoint aRelativePosition( m_xAssociatedShape->getPosition() ); 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir Reference< XTableColumns > xCols( xColsRows->getColumns(), UNO_SET_THROW ); 696*cdf0e10cSrcweir sal_Int32 nNewAnchorCol = lcl_getLowerBoundRowOrColumn( xCols.get(), false, aRelativePosition ); 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir Reference< XTableRows > xRows( xColsRows->getRows(), UNO_SET_THROW ); 699*cdf0e10cSrcweir sal_Int32 nNewAnchorRow = lcl_getLowerBoundRowOrColumn( xRows.get(), true, aRelativePosition ); 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir Reference< XCellRange > xSheetCellRange( xSheet, UNO_QUERY_THROW ); 702*cdf0e10cSrcweir Any aNewAnchorCell( xSheetCellRange->getCellByPosition( nNewAnchorCol, nNewAnchorRow ) ); 703*cdf0e10cSrcweir m_xShapeProperties->setPropertyValue( PROPERTY_ANCHOR, aNewAnchorCell ); 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir break; 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir default: 708*cdf0e10cSrcweir OSL_ENSURE( false, "FormGeometryHandler::impl_setSheetAnchorType_nothrow: illegal anchor type!" ); 709*cdf0e10cSrcweir break; 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir catch( const Exception& ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir //==================================================================== 719*cdf0e10cSrcweir //= ShapeGeometryChangeNotifier - implementation 720*cdf0e10cSrcweir //==================================================================== 721*cdf0e10cSrcweir namespace 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir struct EventTranslation 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir ::rtl::OUString sPropertyName; 726*cdf0e10cSrcweir Any aNewPropertyValue; 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir EventTranslation( const ::rtl::OUString& _propertyName, const Any& _newPropertyValue ) 729*cdf0e10cSrcweir :sPropertyName( _propertyName ) 730*cdf0e10cSrcweir ,aNewPropertyValue( _newPropertyValue ) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir }; 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir //-------------------------------------------------------------------- 737*cdf0e10cSrcweir void SAL_CALL ShapeGeometryChangeNotifier::propertyChange( const PropertyChangeEvent& _event ) throw (RuntimeException) 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir ::comphelper::ComponentMethodGuard aGuard( *this ); 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir ::std::vector< EventTranslation > aEventTranslations; 742*cdf0e10cSrcweir aEventTranslations.reserve(2); 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir if ( _event.PropertyName.equalsAscii( "Position" ) ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir AwtPoint aPos = m_xShape->getPosition(); 747*cdf0e10cSrcweir aEventTranslations.push_back( EventTranslation( PROPERTY_POSITIONX, makeAny( aPos.X ) ) ); 748*cdf0e10cSrcweir aEventTranslations.push_back( EventTranslation( PROPERTY_POSITIONY, makeAny( aPos.Y ) ) ); 749*cdf0e10cSrcweir } 750*cdf0e10cSrcweir else if ( _event.PropertyName.equalsAscii( "Size" ) ) 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir AwtSize aSize = m_xShape->getSize(); 753*cdf0e10cSrcweir aEventTranslations.push_back( EventTranslation( PROPERTY_WIDTH, makeAny( aSize.Width ) ) ); 754*cdf0e10cSrcweir aEventTranslations.push_back( EventTranslation( PROPERTY_HEIGHT, makeAny( aSize.Height ) ) ); 755*cdf0e10cSrcweir } 756*cdf0e10cSrcweir else if ( _event.PropertyName == PROPERTY_ANCHOR_TYPE ) 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir aEventTranslations.push_back( EventTranslation( PROPERTY_TEXT_ANCHOR_TYPE, makeAny( _event.NewValue ) ) ); 759*cdf0e10cSrcweir } 760*cdf0e10cSrcweir else if ( _event.PropertyName == PROPERTY_ANCHOR ) 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir aEventTranslations.push_back( EventTranslation( PROPERTY_SHEET_ANCHOR_TYPE, makeAny( _event.NewValue ) ) ); 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir PropertyChangeEvent aTranslatedEvent( _event ); 766*cdf0e10cSrcweir aTranslatedEvent.Source = m_rParent; 767*cdf0e10cSrcweir 768*cdf0e10cSrcweir aGuard.clear(); 769*cdf0e10cSrcweir for ( ::std::vector< EventTranslation >::const_iterator t = aEventTranslations.begin(); 770*cdf0e10cSrcweir t != aEventTranslations.end(); 771*cdf0e10cSrcweir ++t 772*cdf0e10cSrcweir ) 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir aTranslatedEvent.PropertyName = t->sPropertyName; 775*cdf0e10cSrcweir aTranslatedEvent.NewValue = t->aNewPropertyValue; 776*cdf0e10cSrcweir m_aPropertyChangeListeners.notifyEach( &XPropertyChangeListener::propertyChange, aTranslatedEvent ); 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir //-------------------------------------------------------------------- 781*cdf0e10cSrcweir void SAL_CALL ShapeGeometryChangeNotifier::disposing( const EventObject& /*_event*/ ) throw (RuntimeException) 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir ::comphelper::ComponentMethodGuard aGuard( *this ); 784*cdf0e10cSrcweir impl_dispose_nothrow(); 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir //-------------------------------------------------------------------- 788*cdf0e10cSrcweir void ShapeGeometryChangeNotifier::impl_init_nothrow() 789*cdf0e10cSrcweir { 790*cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 791*cdf0e10cSrcweir try 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir Reference< XPropertySet > xShapeProperties( m_xShape, UNO_QUERY_THROW ); 794*cdf0e10cSrcweir xShapeProperties->addPropertyChangeListener( ::rtl::OUString(), this ); 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir catch( const Exception& ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir //-------------------------------------------------------------------- 804*cdf0e10cSrcweir void ShapeGeometryChangeNotifier::impl_dispose_nothrow() 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir try 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir Reference< XPropertySet > xShapeProperties( m_xShape, UNO_QUERY_THROW ); 809*cdf0e10cSrcweir xShapeProperties->removePropertyChangeListener( ::rtl::OUString(), this ); 810*cdf0e10cSrcweir } 811*cdf0e10cSrcweir catch( const Exception& ) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 814*cdf0e10cSrcweir } 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir getBroadcastHelper().bDisposed = true; 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir //........................................................................ 820*cdf0e10cSrcweir } // namespace pcr 821*cdf0e10cSrcweir //........................................................................ 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_FormGeometryHandler() 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir ::pcr::FormGeometryHandler::registerImplementation(); 826*cdf0e10cSrcweir } 827