Commits

Anonymous committed 6b50ece

CWS-TOOLING: integrate CWS acceleratorsfix01
2009-08-31 06:45:23 +0200 wuy r275582 : i104644 - make the XCUBasedAcceleratorConfiguration::KeyMapping singleton; i104645 - interface storeToStorage of XCUBasedAcceleratorConfiguration is unimplemented
2009-08-31 06:41:51 +0200 wuy r275581 : i104644 - make the XCUBasedAcceleratorConfiguration::KeyMapping singleton
2009-08-14 03:44:15 +0200 wuy r274967 : CWS-TOOLING: rebase CWS acceleratorsfix01 to trunk@274622 (milestone: DEV300:m54)
2009-05-18 11:39:26 +0200 wuy r272007 : CWS-TOOLING: rebase CWS acceleratorsfix01 to trunk@271830 (milestone: DEV300:m48)

  • Participants
  • Parent commits afb3193

Comments (0)

Files changed (2)

File framework/source/accelerators/acceleratorconfiguration.cxx

 // other includes
 #include <vcl/svapp.hxx>
 
-#ifndef __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_
-#include <accelerators/keymapping.hxx>
-#endif
-
 #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
 #include <com/sun/star/container/XNamed.hpp>
 #endif
 													css::uno::RuntimeException         )
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "XCUBasedAcceleratorConfiguration::setKeyEvent" );
-	RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::setKeyEvent" );
+	RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::setKeyEvent" );
 
 	if (
 		(aKeyEvent.KeyCode   == 0) &&
 
 	aWriteLock.unlock();
 	// <- SAFE ----------------------------------
-
-	RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::setKeyEvent" );
 }
 
 //-----------------------------------------------    
 		css::uno::RuntimeException)
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "XCUBasedAcceleratorConfiguration::reload" );
-    RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::reload()" );
+    RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::reload()" );
 
 	// SAFE -> ----------------------------------
 	WriteGuard aWriteLock(m_aLock);
 
 	aWriteLock.unlock();  
 	// <- SAFE ----------------------------------
-
-    RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::reload()" );
 }
 
 //-----------------------------------------------    
 		  css::uno::RuntimeException)
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "XCUBasedAcceleratorConfiguration::reload" );
-    RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::store()" );
+    RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::store()" );
 
     // SAFE -> ----------------------------------
     ReadGuard aReadLock(m_aLock);
 
     aReadLock.unlock();
     // <- SAFE ----------------------------------
-
-    RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::store()" );
 }
 
 //-----------------------------------------------    
-void SAL_CALL XCUBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& /*xStorage*/)
+void SAL_CALL XCUBasedAcceleratorConfiguration::storeToStorage(const css::uno::Reference< css::embed::XStorage >& xStorage)
 	throw(css::uno::Exception       ,
 	  css::uno::RuntimeException)
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "XCUBasedAcceleratorConfiguration::storeToStorage" );
-	// todo implement me
-	// use m_aCache + old AcceleratorXMLWriter to store data directly on storage given as parameter ...  
+    // use m_aCache + old AcceleratorXMLWriter to store data directly on storage given as parameter ...  
+    if (!xStorage.is())
+        return;
+
+    long nOpenModes = css::embed::ElementModes::READWRITE;
+    css::uno::Reference< css::embed::XStorage > xAcceleratorTypeStorage = xStorage->openStorageElement(::rtl::OUString::createFromAscii("accelerator"), nOpenModes);
+    if (!xAcceleratorTypeStorage.is())
+        return;
+
+    css::uno::Reference< css::io::XStream > xStream = xAcceleratorTypeStorage->openStreamElement(::rtl::OUString::createFromAscii("current"), nOpenModes);
+    css::uno::Reference< css::io::XOutputStream > xOut;
+    if (xStream.is())
+        xOut = xStream->getOutputStream();
+    if (!xOut.is())
+        throw css::io::IOException(
+        ::rtl::OUString::createFromAscii("Could not open accelerator configuration for saving."),
+        static_cast< ::cppu::OWeakObject* >(this));
+
+    // the original m_aCache has been split into primay cache and secondary cache...
+    // we should merge them before storing to storage
+    // SAFE -> ----------------------------------
+    WriteGuard aWriteLock(m_aLock);
+
+    AcceleratorCache aCache;
+    if (m_pPrimaryWriteCache != 0)
+        aCache.takeOver(*m_pPrimaryWriteCache);
+    else
+        aCache.takeOver(m_aPrimaryReadCache);
+
+    AcceleratorCache::TKeyList lKeys;
+    AcceleratorCache::TKeyList::const_iterator pIt;
+    if (m_pSecondaryWriteCache!=0)
+    {
+        lKeys = m_pSecondaryWriteCache->getAllKeys();
+        for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt )
+            aCache.setKeyCommandPair(*pIt, m_pSecondaryWriteCache->getCommandByKey(*pIt));
+    }
+    else
+    {
+        lKeys = m_aSecondaryReadCache.getAllKeys();
+        for ( pIt=lKeys.begin(); pIt!=lKeys.end(); ++pIt )
+            aCache.setKeyCommandPair(*pIt, m_aSecondaryReadCache.getCommandByKey(*pIt));
+    }
+
+    aWriteLock.unlock();
+    // <- SAFE ----------------------------------
+
+    css::uno::Reference< css::io::XTruncate > xClearable(xOut, css::uno::UNO_QUERY_THROW);
+    xClearable->truncate();
+    css::uno::Reference< css::io::XSeekable > xSeek(xOut, css::uno::UNO_QUERY);
+    if (xSeek.is())
+        xSeek->seek(0);
+
+    css::uno::Reference< css::xml::sax::XDocumentHandler > xWriter    (m_xSMGR->createInstance(SERVICENAME_SAXWRITER), css::uno::UNO_QUERY_THROW);
+    css::uno::Reference< css::io::XActiveDataSource>       xDataSource(xWriter                                     , css::uno::UNO_QUERY_THROW);
+    xDataSource->setOutputStream(xOut);
+
+    // write into the stream
+    AcceleratorConfigurationWriter aWriter(aCache, xWriter);
+    aWriter.flush();
 }
 
 //-----------------------------------------------    
 	throw(css::uno::RuntimeException)
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "XCUBasedAcceleratorConfiguration::changesOccurred" );
-	RTL_LOGFILE_PRODUCT_CONTEXT( aLog1, " start XCUBasedAcceleratorConfiguration::changesOccurred()" );
+	RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "XCUBasedAcceleratorConfiguration::changesOccurred()" );
 
 	css::uno::Reference< css::container::XHierarchicalNameAccess > xHAccess;
 	aEvent.Base >>= xHAccess;
                 reloadChanged(sPrimarySecondary, sGlobalModules, sModule, sKey);
         }
 	}
-
-	RTL_LOGFILE_PRODUCT_CONTEXT( aLog2, " end XCUBasedAcceleratorConfiguration::changesOccurred()" );
 }
 
 //----------------------------------------------- 
         xModules->getByName(m_sModuleCFG) >>= xAccess;
     }
 
-    static KeyMapping aKeyMapping;
     const ::rtl::OUString sIsoLang       = impl_ts_getLocale().toISO();
 	const ::rtl::OUString sDefaultLocale = ::rtl::OUString::createFromAscii("en-US");
 
             sal_Int32 nIndex = 0;
             ::rtl::OUString sKeyCommand = sKey.getToken(0, '_', nIndex);
             ::rtl::OUString sPrefix = ::rtl::OUString::createFromAscii("KEY_");
-            aKeyEvent.KeyCode = aKeyMapping.mapIdentifierToCode(sPrefix + sKeyCommand);
+            aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(sPrefix + sKeyCommand);
 
             css::uno::Sequence< ::rtl::OUString > sToken(4);
             const sal_Int32 nToken = 4;
         xModules->getByName(sModule) >>= xContainer;
     }
 
-	KeyMapping aKeyMapping;
 	css::awt::KeyEvent aKeyEvent;
 	::rtl::OUString sKeyIdentifier;
 
 	sal_Int32 nIndex = 0;
 	sKeyIdentifier = sKey.getToken(0, '_', nIndex);
-	aKeyEvent.KeyCode = aKeyMapping.mapIdentifierToCode(::rtl::OUString::createFromAscii("KEY_")+sKeyIdentifier);
+	aKeyEvent.KeyCode = m_rKeyMapping->mapIdentifierToCode(::rtl::OUString::createFromAscii("KEY_")+sKeyIdentifier);
 
 	css::uno::Sequence< ::rtl::OUString > sToken(3);
 	const sal_Int32 nToken = 3;
 }
 
 } // namespace framework
-

File framework/source/inc/accelerators/acceleratorconfiguration.hxx

 #include <accelerators/istoragelistener.hxx>
 #include <accelerators/presethandler.hxx>
 #include <accelerators/acceleratorcache.hxx>
+#include <accelerators/keymapping.hxx>
 #include <macros/xinterface.hxx>
 #include <macros/xtypeprovider.hxx>
 #include <threadhelp/threadhelpbase.hxx>
 #include <cppuhelper/propshlp.hxx>
 #include <cppuhelper/weak.hxx>
 #include <comphelper/locale.hxx>
+#include <salhelper/singletonref.hxx>
 
 //__________________________________________
 // definition
         ::rtl::OUString m_sGlobalOrModules;
 		::rtl::OUString m_sModuleCFG;
 
+        ::salhelper::SingletonRef< KeyMapping > m_rKeyMapping;
+
 		//______________________________________
 		// native interface!