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