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