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