1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_ 25 #define __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_ 26 27 //__________________________________________ 28 // own includes 29 30 #include <accelerators/istoragelistener.hxx> 31 #include <accelerators/presethandler.hxx> 32 #include <accelerators/acceleratorcache.hxx> 33 #include <accelerators/keymapping.hxx> 34 #include <macros/xinterface.hxx> 35 #include <macros/xtypeprovider.hxx> 36 #include <threadhelp/threadhelpbase.hxx> 37 #include <general.h> 38 #include <stdtypes.h> 39 40 //__________________________________________ 41 // interface includes 42 43 #include <com/sun/star/container/XNameAccess.hpp> 44 #include <com/sun/star/lang/XTypeProvider.hpp> 45 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 46 #include <com/sun/star/ui/XAcceleratorConfiguration.hpp> 47 #include <com/sun/star/ui/XUIConfiguration.hpp> 48 #include <com/sun/star/ui/XUIConfigurationPersistence.hpp> 49 50 #include <com/sun/star/ui/XUIConfigurationStorage.hpp> 51 #include <com/sun/star/io/XStream.hpp> 52 #include <com/sun/star/io/XInputStream.hpp> 53 #include <com/sun/star/io/XOutputStream.hpp> 54 #include <com/sun/star/util/XChangesListener.hpp> 55 56 // TODO use XPresetHandler interface instead if available 57 #include <com/sun/star/form/XReset.hpp> 58 59 //__________________________________________ 60 // other includes 61 #include <cppuhelper/propshlp.hxx> 62 #include <cppuhelper/weak.hxx> 63 #include <comphelper/locale.hxx> 64 #include <salhelper/singletonref.hxx> 65 66 //__________________________________________ 67 // definition 68 69 namespace framework 70 { 71 //----------------------------------------------- 72 // Accelerators.xcu 73 74 static const ::rtl::OUString CFG_ENTRY_PRIMARY = ::rtl::OUString::createFromAscii("PrimaryKeys"); 75 static const ::rtl::OUString CFG_ENTRY_SECONDARY = ::rtl::OUString::createFromAscii("SecondaryKeys"); 76 77 static const ::rtl::OUString CFG_ENTRY_GLOBAL = ::rtl::OUString::createFromAscii("Global"); 78 static const ::rtl::OUString CFG_ENTRY_MODULES = ::rtl::OUString::createFromAscii("Modules"); 79 80 static const ::rtl::OUString CFG_PROP_COMMAND = ::rtl::OUString::createFromAscii("Command"); 81 82 /** "global" type to make accelerator presets unique, so they can be used 83 in combination with the salhelper::SingletonRef mechanism! */ 84 typedef PresetHandler AcceleratorPresets; 85 86 //__________________________________________ 87 /** 88 implements a read/write access to the accelerator configuration. 89 */ 90 class XMLBasedAcceleratorConfiguration : protected ThreadHelpBase // attention! Must be the first base class to guarantee right initialize lock ... 91 , public IStorageListener 92 , public ::cppu::OWeakObject 93 , public css::lang::XTypeProvider 94 , public css::form::XReset // TODO use XPresetHandler instead if available 95 , public css::ui::XAcceleratorConfiguration // => css::ui::XUIConfigurationPersistence 96 // css::ui::XUIConfigurationStorage 97 // css::ui::XUIConfiguration 98 { 99 //______________________________________ 100 // member 101 102 protected: 103 104 //--------------------------------------- 105 /** the global uno service manager. 106 Must be used to create own needed services. */ 107 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 108 109 //--------------------------------------- 110 /** used to: 111 i ) copy configuration files from the share to the user layer 112 ii ) provide access to these config files 113 iii) cache all sub storages on the path from the top to the bottom(!) 114 iv ) provide commit for changes. */ 115 PresetHandler m_aPresetHandler; 116 117 //--------------------------------------- 118 /** contains the cached configuration data */ 119 AcceleratorCache m_aReadCache; 120 121 //--------------------------------------- 122 /** used to implement the copy on write pattern! */ 123 AcceleratorCache* m_pWriteCache; 124 125 //______________________________________ 126 // native interface! 127 128 public: 129 130 XMLBasedAcceleratorConfiguration( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR ); 131 virtual ~XMLBasedAcceleratorConfiguration( ); 132 133 //______________________________________ 134 // uno interface! 135 136 public: 137 138 // XInterface, XTypeProvider 139 FWK_DECLARE_XINTERFACE 140 FWK_DECLARE_XTYPEPROVIDER 141 142 // XAcceleratorConfiguration 143 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents(); 144 145 virtual ::rtl::OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent); 146 147 virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent& aKeyEvent, 148 const ::rtl::OUString& sCommand ); 149 150 virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent& aKeyEvent); 151 152 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const ::rtl::OUString& sCommand); 153 154 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList); 155 156 virtual void SAL_CALL removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand); 157 158 // XUIConfigurationPersistence 159 virtual void SAL_CALL reload(); 160 161 virtual void SAL_CALL store(); 162 163 virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage); 164 165 virtual ::sal_Bool SAL_CALL isModified(); 166 167 virtual ::sal_Bool SAL_CALL isReadOnly(); 168 169 // XUIConfigurationStorage 170 virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage); 171 172 virtual ::sal_Bool SAL_CALL hasStorage(); 173 174 // XUIConfiguration 175 virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener); 176 177 virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener); 178 179 // XReset 180 // TODO use XPresetHandler instead if available 181 virtual void SAL_CALL reset(); 182 183 virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener >& xListener); 184 185 virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener >& xListener); 186 187 // IStorageListener 188 virtual void changesOccured(const ::rtl::OUString& sPath); 189 190 //______________________________________ 191 // helper for derived classes 192 193 protected: 194 195 //--------------------------------------- 196 /** @short return the current office locale. 197 198 @descr We does not cache this value, because we are not listen 199 for changes on the configuration layer ... 200 201 @return ::comphelper::Locale 202 The current office locale. 203 */ 204 ::comphelper::Locale impl_ts_getLocale() const; 205 206 //______________________________________ 207 // helper 208 209 private: 210 211 //--------------------------------------- 212 /** @short load a configuration set, using the given stream. 213 214 @param xStream 215 provides the XML structure as stream. 216 */ 217 void impl_ts_load(const css::uno::Reference< css::io::XInputStream >& xStream); 218 219 //--------------------------------------- 220 /** @short save a configuration set, using the given stream. 221 222 @param xStream 223 the XML structure can be written there. 224 */ 225 void impl_ts_save(const css::uno::Reference< css::io::XOutputStream >& xStream); 226 227 //--------------------------------------- 228 /** @short try to locate and open a sub storage. 229 230 @descr It search at the root storage for the specified 231 sub storage. If it exists - it will be opened. 232 By default this method tries to open the storage 233 for reading. But the calli can request a writeable 234 storage. 235 236 @param xRooStorage 237 used to locate the sub storage. 238 239 @param sSubStorage 240 relativ path of the sub storage. 241 242 @param bOutStream 243 force open of the sub storage in 244 write mode - instead of read mode, which 245 is the default. 246 247 @return [XInterface] 248 will be a css::io::XInpoutStream or a css::io::XOutputStream. 249 Depends from the parameter bWriteable! 250 */ 251 css::uno::Reference< css::uno::XInterface > impl_ts_openSubStorage(const css::uno::Reference< css::embed::XStorage >& xRootStorage, 252 const ::rtl::OUString& sSubStorage , 253 sal_Bool bOutStream ); 254 255 //--------------------------------------- 256 /** @short returns a reference to one of our internal cache members. 257 258 @descr We implement the copy-on-write pattern. Doing so 259 we know two caches internally. The second one is used 260 only, if the container was changed. 261 262 This method here returns access to one of these 263 caches - depending on the change state of this 264 configuration service. 265 266 @param bWriteAccessRequested 267 if the outside code whish to change the container 268 it must call this method with "sal_True". So the internal 269 cache can be prepared for that (means copy-on-write ...). 270 271 @return [AcceleratorCache] 272 c++ reference(!) to one of our internal caches. 273 */ 274 AcceleratorCache& impl_getCFG(sal_Bool bWriteAccessRequested = sal_False); 275 276 }; 277 278 class XCUBasedAcceleratorConfiguration : protected ThreadHelpBase // attention! Must be the first base class to guarantee right initialize lock ... 279 , public ::cppu::OWeakObject 280 , public css::lang::XTypeProvider 281 , public css::util::XChangesListener 282 , public css::lang::XComponent 283 , public css::form::XReset // TODO use XPresetHandler instead if available 284 , public css::ui::XAcceleratorConfiguration // => css::ui::XUIConfigurationPersistence 285 // css::ui::XUIConfigurationStorage 286 // css::ui::XUIConfiguration 287 { 288 //______________________________________ 289 // member 290 291 protected: 292 293 //--------------------------------------- 294 /** the global uno service manager. 295 Must be used to create own needed services. */ 296 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 297 298 css::uno::Reference< css::container::XNameAccess > m_xCfg; 299 AcceleratorCache m_aPrimaryReadCache; 300 AcceleratorCache m_aSecondaryReadCache; 301 AcceleratorCache* m_pPrimaryWriteCache; 302 AcceleratorCache* m_pSecondaryWriteCache; 303 304 ::rtl::OUString m_sGlobalOrModules; 305 ::rtl::OUString m_sModuleCFG; 306 307 ::salhelper::SingletonRef< KeyMapping > m_rKeyMapping; 308 309 //______________________________________ 310 // native interface! 311 312 public: 313 314 XCUBasedAcceleratorConfiguration( const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR ); 315 virtual ~XCUBasedAcceleratorConfiguration( ); 316 317 //______________________________________ 318 // uno interface! 319 320 public: 321 322 // XInterface, XTypeProvider 323 FWK_DECLARE_XINTERFACE 324 FWK_DECLARE_XTYPEPROVIDER 325 326 // XAcceleratorConfiguration 327 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getAllKeyEvents(); 328 329 virtual ::rtl::OUString SAL_CALL getCommandByKeyEvent(const css::awt::KeyEvent& aKeyEvent); 330 331 virtual void SAL_CALL setKeyEvent(const css::awt::KeyEvent& aKeyEvent, 332 const ::rtl::OUString& sCommand ); 333 334 virtual void SAL_CALL removeKeyEvent(const css::awt::KeyEvent& aKeyEvent); 335 336 virtual css::uno::Sequence< css::awt::KeyEvent > SAL_CALL getKeyEventsByCommand(const ::rtl::OUString& sCommand); 337 338 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPreferredKeyEventsForCommandList(const css::uno::Sequence< ::rtl::OUString >& lCommandList); 339 340 virtual void SAL_CALL removeCommandFromAllKeyEvents(const ::rtl::OUString& sCommand); 341 342 // XUIConfigurationPersistence 343 virtual void SAL_CALL reload(); 344 345 virtual void SAL_CALL store(); 346 347 virtual void SAL_CALL storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage); 348 349 virtual ::sal_Bool SAL_CALL isModified(); 350 351 virtual ::sal_Bool SAL_CALL isReadOnly(); 352 353 // XUIConfigurationStorage 354 virtual void SAL_CALL setStorage(const css::uno::Reference< css::embed::XStorage >& xStorage); 355 356 virtual ::sal_Bool SAL_CALL hasStorage(); 357 358 // XUIConfiguration 359 virtual void SAL_CALL addConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener); 360 361 virtual void SAL_CALL removeConfigurationListener(const css::uno::Reference< css::ui::XUIConfigurationListener >& xListener); 362 363 // XReset 364 // TODO use XPresetHandler instead if available 365 virtual void SAL_CALL reset(); 366 367 virtual void SAL_CALL addResetListener(const css::uno::Reference< css::form::XResetListener >& xListener); 368 369 virtual void SAL_CALL removeResetListener(const css::uno::Reference< css::form::XResetListener >& xListener); 370 371 // css.util.XChangesListener 372 virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent); 373 374 // css.lang.XEventListener 375 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent); 376 377 // XComponent 378 virtual void SAL_CALL dispose(); 379 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ); 380 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ); 381 382 //______________________________________ 383 // helper for derived classes 384 385 protected: 386 387 //--------------------------------------- 388 /** @short return the current office locale. 389 390 @descr We does not cache this value, because we are not listen 391 for changes on the configuration layer ... 392 393 @return ::comphelper::Locale 394 The current office locale. 395 */ 396 ::comphelper::Locale impl_ts_getLocale() const; 397 398 //______________________________________ 399 // helper 400 401 private: 402 403 void impl_ts_load(sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg); 404 void impl_ts_save(sal_Bool bPreferred, const css::uno::Reference< css::container::XNameAccess >& xCfg); 405 406 void insertKeyToConfiguration(const css::awt::KeyEvent& aKeyEvent, const ::rtl::OUString& sCommand, const sal_Bool bPreferred); 407 void removeKeyFromConfiguration(const css::awt::KeyEvent& aKeyEvent, const sal_Bool bPreferred); 408 409 void reloadChanged(const ::rtl::OUString& sPrimarySecondary, const ::rtl::OUString& sGlobalModules, const ::rtl::OUString& sModule, const ::rtl::OUString& sKey); 410 AcceleratorCache& impl_getCFG(sal_Bool bPreferred, sal_Bool bWriteAccessRequested = sal_False); 411 412 }; 413 414 } // namespace framework 415 416 #endif // __FRAMEWORK_ACCELERATORS_ACCELERATORCONFIGURATION_HXX_ 417