1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SVX_FORMCONTROLLING_HXX 29*cdf0e10cSrcweir #define SVX_FORMCONTROLLING_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormController.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/form/runtime/FeatureState.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/form/runtime/XFormOperations.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLErrorListener.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 39*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <vector> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //........................................................................ 44*cdf0e10cSrcweir namespace svx 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir //........................................................................ 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir //==================================================================== 49*cdf0e10cSrcweir //= FeatureSlotTranslation 50*cdf0e10cSrcweir //==================================================================== 51*cdf0e10cSrcweir class FeatureSlotTranslation 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir public: 54*cdf0e10cSrcweir /// retrieves the feature id for a given feature URL 55*cdf0e10cSrcweir static sal_Int32 getControllerFeatureSlotIdForURL( const ::rtl::OUString& _rMainURL ); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir /// retrieves the feature URL for a given feature id 58*cdf0e10cSrcweir static ::rtl::OUString getControllerFeatureURLForSlotId( sal_Int32 _nSlotId ); 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir /// determines whether the given URL is a controller feature URL 61*cdf0e10cSrcweir static sal_Bool isFeatureURL( const ::rtl::OUString& _rMainURL ); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /// retrieves the css.form.runtime.FormFeature ID for a given slot ID 64*cdf0e10cSrcweir static sal_Int16 getFormFeatureForSlotId( sal_Int32 _nSlotId ); 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir /// retrieves the slot id for a given css.form.runtime.FormFeature ID 67*cdf0e10cSrcweir static sal_Int32 getSlotIdForFormFeature( sal_Int16 _nFormFeature ); 68*cdf0e10cSrcweir }; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //==================================================================== 71*cdf0e10cSrcweir //= IControllerFeatureInvalidation 72*cdf0e10cSrcweir //==================================================================== 73*cdf0e10cSrcweir class IControllerFeatureInvalidation 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir public: 76*cdf0e10cSrcweir /** invalidates the given features 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir Invalidation means that any user interface representation (such as toolbox buttons), or 79*cdf0e10cSrcweir any dispatches associated with the features in question are potentially out-of-date, and 80*cdf0e10cSrcweir need to be updated 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir @param _rFeatures 83*cdf0e10cSrcweir Ids of the features to be invalidated. 84*cdf0e10cSrcweir */ 85*cdf0e10cSrcweir virtual void invalidateFeatures( const ::std::vector< sal_Int32 >& _rFeatures ) = 0; 86*cdf0e10cSrcweir }; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //==================================================================== 89*cdf0e10cSrcweir //= ControllerFeatures 90*cdf0e10cSrcweir //==================================================================== 91*cdf0e10cSrcweir class FormControllerHelper; 92*cdf0e10cSrcweir /** easier access to an FormControllerHelper instance 93*cdf0e10cSrcweir */ 94*cdf0e10cSrcweir class ControllerFeatures 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir protected: 97*cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 98*cdf0e10cSrcweir IControllerFeatureInvalidation* m_pInvalidationCallback; // necessary as long as m_pImpl is not yet constructed 99*cdf0e10cSrcweir FormControllerHelper* m_pImpl; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir public: 102*cdf0e10cSrcweir /** standard ctor 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir The instance is not functional until <method>assign</method> is used. 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir @param _rxORB 107*cdf0e10cSrcweir a multi service factory for creating various needed components 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir @param _pInvalidationCallback 110*cdf0e10cSrcweir the callback for invalidating feature states 111*cdf0e10cSrcweir */ 112*cdf0e10cSrcweir ControllerFeatures( 113*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 114*cdf0e10cSrcweir IControllerFeatureInvalidation* _pInvalidationCallback 115*cdf0e10cSrcweir ); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir /** constructs the instance from a <type scope="com::sun::star::form::runtime">XFormController<type> instance 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir @param _rxORB 120*cdf0e10cSrcweir a multi service factory for creating various needed components 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir @param _rxController 123*cdf0e10cSrcweir The form controller which the helper should be responsible for. Must not 124*cdf0e10cSrcweir be <NULL/>, and must have a valid model (form). 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir @param _pInvalidationCallback 127*cdf0e10cSrcweir the callback for invalidating feature states 128*cdf0e10cSrcweir */ 129*cdf0e10cSrcweir ControllerFeatures( 130*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 131*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController, 132*cdf0e10cSrcweir IControllerFeatureInvalidation* _pInvalidationCallback 133*cdf0e10cSrcweir ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir /** constructs the helper form a <type scope="com::sun::star::form">XForm<type> instance 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir Any functionality which depends on a controller will not be available. 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir @param _rxORB 140*cdf0e10cSrcweir a multi service factory for creating various needed components 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir @param _rxForm 143*cdf0e10cSrcweir The form which the helper should be responsible for. Must not be <NULL/>. 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir @param _pInvalidationCallback 146*cdf0e10cSrcweir the callback for invalidating feature states 147*cdf0e10cSrcweir */ 148*cdf0e10cSrcweir ControllerFeatures( 149*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 150*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm, 151*cdf0e10cSrcweir IControllerFeatureInvalidation* _pInvalidationCallback 152*cdf0e10cSrcweir ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir /// dtor 155*cdf0e10cSrcweir ~ControllerFeatures(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /// checks whether the instance is properly assigned to a form and/or controller 158*cdf0e10cSrcweir inline bool isAssigned( ) const { return m_pImpl != NULL; } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir /** assign to a controller 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir void assign( 163*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController 164*cdf0e10cSrcweir ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir /** assign to a controller 167*cdf0e10cSrcweir */ 168*cdf0e10cSrcweir void assign( 169*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm 170*cdf0e10cSrcweir ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir /// clears the instance so that it cannot be used afterwards 173*cdf0e10cSrcweir void dispose(); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir // access to the instance which implements the functionality. Not to be used when not assigned 176*cdf0e10cSrcweir inline const FormControllerHelper* operator->() const { return m_pImpl; } 177*cdf0e10cSrcweir inline FormControllerHelper* operator->() { return m_pImpl; } 178*cdf0e10cSrcweir inline const FormControllerHelper& operator*() const { return *m_pImpl; } 179*cdf0e10cSrcweir inline FormControllerHelper& operator*() { return *m_pImpl; } 180*cdf0e10cSrcweir }; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //==================================================================== 183*cdf0e10cSrcweir //= FormControllerHelper 184*cdf0e10cSrcweir //==================================================================== 185*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2 < ::com::sun::star::form::runtime::XFeatureInvalidation 186*cdf0e10cSrcweir , ::com::sun::star::sdb::XSQLErrorListener 187*cdf0e10cSrcweir > FormControllerHelper_Base; 188*cdf0e10cSrcweir /** is a helper class which manages form controller functionality (such as moveNext etc.). 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir <p>The class helps implementing form controller functionality, by providing 191*cdf0e10cSrcweir methods to determine the state of, and execute, various common form features.<br/> 192*cdf0e10cSrcweir A <em>feature</em> is for instance moving the form associated with the controller 193*cdf0e10cSrcweir to a certain position, or reloading the form, and so on.</p> 194*cdf0e10cSrcweir */ 195*cdf0e10cSrcweir class FormControllerHelper : public FormControllerHelper_Base 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir protected: 198*cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 199*cdf0e10cSrcweir IControllerFeatureInvalidation* m_pInvalidationCallback; 200*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations > 201*cdf0e10cSrcweir m_xFormOperations; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir ::com::sun::star::uno::Any m_aOperationError; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir public: 206*cdf0e10cSrcweir /** constructs the helper from a <type scope="com::sun::star::form::runtime">XFormController<type> instance 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir @param _rContext 209*cdf0e10cSrcweir the context the component lives in 210*cdf0e10cSrcweir @param _rxController 211*cdf0e10cSrcweir The form controller which the helper should be responsible for. Must not 212*cdf0e10cSrcweir be <NULL/>, and must have a valid model (form). 213*cdf0e10cSrcweir @param _pInvalidationCallback 214*cdf0e10cSrcweir the callback for invalidating feature states 215*cdf0e10cSrcweir */ 216*cdf0e10cSrcweir FormControllerHelper( 217*cdf0e10cSrcweir const ::comphelper::ComponentContext& _rContext, 218*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormController >& _rxController, 219*cdf0e10cSrcweir IControllerFeatureInvalidation* _pInvalidationCallback 220*cdf0e10cSrcweir ); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir /** constructs the helper form a <type scope="com::sun::star::form">XForm<type> instance 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir Any functionality which depends on a controller will not be available. 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir @param _rContext 227*cdf0e10cSrcweir the context the component lives in 228*cdf0e10cSrcweir @param _rxForm 229*cdf0e10cSrcweir The form which the helper should be responsible for. Must not be <NULL/>. 230*cdf0e10cSrcweir @param _pInvalidationCallback 231*cdf0e10cSrcweir the callback for invalidating feature states 232*cdf0e10cSrcweir */ 233*cdf0e10cSrcweir FormControllerHelper( 234*cdf0e10cSrcweir const ::comphelper::ComponentContext& _rContext, 235*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& _rxForm, 236*cdf0e10cSrcweir IControllerFeatureInvalidation* _pInvalidationCallback 237*cdf0e10cSrcweir ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // forwards to the XFormOperations implementation 240*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > 241*cdf0e10cSrcweir getCursor() const; 242*cdf0e10cSrcweir void getState( 243*cdf0e10cSrcweir sal_Int32 _nSlotId, 244*cdf0e10cSrcweir ::com::sun::star::form::runtime::FeatureState& _out_rState 245*cdf0e10cSrcweir ) const; 246*cdf0e10cSrcweir sal_Bool isEnabled( sal_Int32 _nSlotId ) const; 247*cdf0e10cSrcweir void execute( sal_Int32 _nSlotId ) const; 248*cdf0e10cSrcweir void execute( sal_Int32 _nSlotId, const ::rtl::OUString& _rParamName, const ::com::sun::star::uno::Any& _rParamValue ) const; 249*cdf0e10cSrcweir sal_Bool commitCurrentRecord() const; 250*cdf0e10cSrcweir sal_Bool commitCurrentControl( ) const; 251*cdf0e10cSrcweir sal_Bool isInsertionRow() const; 252*cdf0e10cSrcweir sal_Bool isModifiedRow() const; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir bool moveLeft( ) const; 255*cdf0e10cSrcweir bool moveRight( ) const; 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir bool canDoFormFilter() const; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir /** disposes this instance. 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir After this method has been called, the instance is not functional anymore 262*cdf0e10cSrcweir */ 263*cdf0e10cSrcweir void dispose(); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::form::runtime::XFormOperations >& 266*cdf0e10cSrcweir getFormOperations() const { return m_xFormOperations; } 267*cdf0e10cSrcweir protected: 268*cdf0e10cSrcweir /// dtor 269*cdf0e10cSrcweir ~FormControllerHelper(); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // XFeatureInvalidation 272*cdf0e10cSrcweir virtual void SAL_CALL invalidateFeatures( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& Features ) throw (::com::sun::star::uno::RuntimeException); 273*cdf0e10cSrcweir virtual void SAL_CALL invalidateAllFeatures() throw (::com::sun::star::uno::RuntimeException); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir // XSQLErrorListener 276*cdf0e10cSrcweir virtual void SAL_CALL errorOccured( const ::com::sun::star::sdb::SQLErrorEvent& _Event ) throw (::com::sun::star::uno::RuntimeException); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir // XEventListener 279*cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir private: 282*cdf0e10cSrcweir enum FormOperation { EXECUTE, EXECUTE_ARGS, COMMIT_CONTROL, COMMIT_RECORD }; 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir bool impl_operateForm_nothrow( 285*cdf0e10cSrcweir const FormOperation _eWhat, 286*cdf0e10cSrcweir const sal_Int16 _nFeature, /* ignore for COMMIT_* */ 287*cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rArguments /* ignore except for EXECUTE_ARGS */ 288*cdf0e10cSrcweir ) const; 289*cdf0e10cSrcweir bool impl_operateForm_nothrow( const FormOperation _eWhat ) const 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir return impl_operateForm_nothrow( _eWhat, 0, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir bool impl_operateForm_nothrow( const sal_Int16 _nFeature ) const 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir return impl_operateForm_nothrow( EXECUTE, _nFeature, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >() ); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir private: 299*cdf0e10cSrcweir FormControllerHelper(); // never implemented 300*cdf0e10cSrcweir FormControllerHelper( const FormControllerHelper& ); // never implemented 301*cdf0e10cSrcweir FormControllerHelper& operator=( const FormControllerHelper& ); // never implemented 302*cdf0e10cSrcweir }; 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //........................................................................ 305*cdf0e10cSrcweir } // namespace svx 306*cdf0e10cSrcweir //........................................................................ 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir #endif // SVX_FORMCONTROLLING_HXX 309