1b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b5088357SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b5088357SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b5088357SAndrew Rist * distributed with this work for additional information
6b5088357SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b5088357SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b5088357SAndrew Rist * "License"); you may not use this file except in compliance
9b5088357SAndrew Rist * with the License. You may obtain a copy of the License at
10b5088357SAndrew Rist *
11b5088357SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b5088357SAndrew Rist *
13b5088357SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b5088357SAndrew Rist * software distributed under the License is distributed on an
15b5088357SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b5088357SAndrew Rist * KIND, either express or implied. See the License for the
17b5088357SAndrew Rist * specific language governing permissions and limitations
18b5088357SAndrew Rist * under the License.
19b5088357SAndrew Rist *
20b5088357SAndrew Rist *************************************************************/
21b5088357SAndrew Rist
22b5088357SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <unotools/eventcfg.hxx>
28cdf0e10cSrcweir #include <unotools/configmgr.hxx>
29cdf0e10cSrcweir #include <unotools/configitem.hxx>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
34cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #ifndef __SGI_STL_HASH_MAP
37cdf0e10cSrcweir #include <hash_map>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <tools/urlobj.hxx>
40cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <itemholder1.hxx>
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include <algorithm>
45cdf0e10cSrcweir
46cdf0e10cSrcweir using namespace ::std ;
47cdf0e10cSrcweir using namespace ::utl ;
48cdf0e10cSrcweir using namespace ::rtl ;
49cdf0e10cSrcweir using namespace ::osl ;
50cdf0e10cSrcweir using namespace ::com::sun::star::uno ;
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir
53cdf0e10cSrcweir #define ROOTNODE_EVENTS OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Events/ApplicationEvents" ))
54cdf0e10cSrcweir #define PATHDELIMITER OUString(RTL_CONSTASCII_USTRINGPARAM("/"))
55cdf0e10cSrcweir #define SETNODE_BINDINGS OUString(RTL_CONSTASCII_USTRINGPARAM("Bindings" ))
56cdf0e10cSrcweir #define PROPERTYNAME_BINDINGURL OUString(RTL_CONSTASCII_USTRINGPARAM("BindingURL"))
57cdf0e10cSrcweir
58cdf0e10cSrcweir const char* pEventAsciiNames[] =
59cdf0e10cSrcweir {
60cdf0e10cSrcweir "OnStartApp",
61cdf0e10cSrcweir "OnCloseApp",
62cdf0e10cSrcweir "OnCreate",
63cdf0e10cSrcweir "OnNew",
64cdf0e10cSrcweir "OnLoadFinished",
65cdf0e10cSrcweir "OnLoad",
66cdf0e10cSrcweir "OnPrepareUnload",
67cdf0e10cSrcweir "OnUnload",
68cdf0e10cSrcweir "OnSave",
69cdf0e10cSrcweir "OnSaveDone",
70cdf0e10cSrcweir "OnSaveFailed",
71cdf0e10cSrcweir "OnSaveAs",
72cdf0e10cSrcweir "OnSaveAsDone",
73cdf0e10cSrcweir "OnSaveAsFailed",
74cdf0e10cSrcweir "OnCopyTo",
75cdf0e10cSrcweir "OnCopyToDone",
76cdf0e10cSrcweir "OnCopyToFailed",
77cdf0e10cSrcweir "OnFocus",
78cdf0e10cSrcweir "OnUnfocus",
79cdf0e10cSrcweir "OnPrint",
80cdf0e10cSrcweir "OnViewCreated",
81cdf0e10cSrcweir "OnPrepareViewClosing",
82cdf0e10cSrcweir "OnViewClosed",
83cdf0e10cSrcweir "OnModifyChanged",
84cdf0e10cSrcweir "OnTitleChanged",
85cdf0e10cSrcweir "OnVisAreaChanged",
86cdf0e10cSrcweir "OnModeChanged",
87cdf0e10cSrcweir "OnStorageChanged"
88cdf0e10cSrcweir };
89cdf0e10cSrcweir
GlobalEventConfig_Impl()90cdf0e10cSrcweir GlobalEventConfig_Impl::GlobalEventConfig_Impl()
91cdf0e10cSrcweir : ConfigItem( ROOTNODE_EVENTS, CONFIG_MODE_IMMEDIATE_UPDATE )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir // the supported event names
94cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_STARTAPP] ) );
95cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_CLOSEAPP] ) );
96cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_DOCCREATED] ) );
97cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_CREATEDOC] ) );
98cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_LOADFINISHED] ) );
99cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_OPENDOC] ) );
100cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_PREPARECLOSEDOC] ) );
101cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_CLOSEDOC] ) );
102cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVEDOC] ) );
103cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVEDOCDONE] ) );
104cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVEDOCFAILED] ) );
105cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVEASDOC] ) );
106cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVEASDOCDONE] ) );
107cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVEASDOCFAILED] ) );
108cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVETODOC] ) );
109cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVETODOCDONE] ) );
110cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_SAVETODOCFAILED] ) );
111cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_ACTIVATEDOC] ) );
112cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_DEACTIVATEDOC] ) );
113cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_PRINTDOC] ) );
114cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_VIEWCREATED] ) );
115cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_PREPARECLOSEVIEW] ) );
116cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_CLOSEVIEW] ) );
117cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_MODIFYCHANGED] ) );
118cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_TITLECHANGED] ) );
119cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_VISAREACHANGED] ) );
120cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_MODECHANGED] ) );
121cdf0e10cSrcweir m_supportedEvents.push_back(::rtl::OUString::createFromAscii( pEventAsciiNames[STR_EVENT_STORAGECHANGED] ) );
122cdf0e10cSrcweir
123cdf0e10cSrcweir initBindingInfo();
124cdf0e10cSrcweir
125cdf0e10cSrcweir /*TODO: Not used in the moment! see Notify() ...
126cdf0e10cSrcweir // Enable notification mechanism of our baseclass.
127cdf0e10cSrcweir // We need it to get information about changes outside these class on our used configuration keys! */
128cdf0e10cSrcweir Sequence< OUString > aNotifySeq( 1 );
129cdf0e10cSrcweir aNotifySeq[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( "Events" ));
130cdf0e10cSrcweir EnableNotification( aNotifySeq, sal_True );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir //*****************************************************************************************************************
134cdf0e10cSrcweir // destructor
135cdf0e10cSrcweir //*****************************************************************************************************************
~GlobalEventConfig_Impl()136cdf0e10cSrcweir GlobalEventConfig_Impl::~GlobalEventConfig_Impl()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir // We must save our current values .. if user forget it!
139cdf0e10cSrcweir if( IsModified() == sal_True )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir Commit();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
GetEventName(sal_Int32 nIndex)145cdf0e10cSrcweir ::rtl::OUString GlobalEventConfig_Impl::GetEventName( sal_Int32 nIndex )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir if ( nIndex < (sal_Int32) m_supportedEvents.size() )
148cdf0e10cSrcweir return m_supportedEvents[nIndex];
149cdf0e10cSrcweir else
150cdf0e10cSrcweir return rtl::OUString();
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir //*****************************************************************************************************************
154cdf0e10cSrcweir // public method
155cdf0e10cSrcweir //*****************************************************************************************************************
Notify(const Sequence<OUString> &)156cdf0e10cSrcweir void GlobalEventConfig_Impl::Notify( const Sequence< OUString >& )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir MutexGuard aGuard( GlobalEventConfig::GetOwnStaticMutex() );
159cdf0e10cSrcweir
160cdf0e10cSrcweir initBindingInfo();
161cdf0e10cSrcweir
162cdf0e10cSrcweir // dont forget to update all existing frames and her might cached dispatch objects!
163cdf0e10cSrcweir // But look for already killed frames. We hold weak references instead of hard ones ...
164cdf0e10cSrcweir for (FrameVector::const_iterator pIt = m_lFrames.begin();
165cdf0e10cSrcweir pIt != m_lFrames.end() ;
166cdf0e10cSrcweir ++pIt )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame(pIt->get(), ::com::sun::star::uno::UNO_QUERY);
169cdf0e10cSrcweir if (xFrame.is())
170cdf0e10cSrcweir xFrame->contextChanged();
171cdf0e10cSrcweir }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir //*****************************************************************************************************************
175cdf0e10cSrcweir // public method
176cdf0e10cSrcweir //*****************************************************************************************************************
Commit()177cdf0e10cSrcweir void GlobalEventConfig_Impl::Commit()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir //DF need to check it this is correct??
180cdf0e10cSrcweir OSL_TRACE("In GlobalEventConfig_Impl::Commit");
181cdf0e10cSrcweir EventBindingHash::const_iterator it = m_eventBindingHash.begin();
182cdf0e10cSrcweir EventBindingHash::const_iterator it_end = m_eventBindingHash.end();
183cdf0e10cSrcweir // clear the existing nodes
184cdf0e10cSrcweir ClearNodeSet( SETNODE_BINDINGS );
185cdf0e10cSrcweir Sequence< beans::PropertyValue > seqValues( 1 );
186cdf0e10cSrcweir OUString sNode;
187cdf0e10cSrcweir static const OUString sPrefix(SETNODE_BINDINGS + PATHDELIMITER + OUString::createFromAscii("BindingType['"));
188cdf0e10cSrcweir static const OUString sPostfix(OUString::createFromAscii("']") + PATHDELIMITER + PROPERTYNAME_BINDINGURL);
189cdf0e10cSrcweir //step through the list of events
190cdf0e10cSrcweir for(int i=0;it!=it_end;++it,++i)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir //no point in writing out empty bindings!
193cdf0e10cSrcweir if(it->second.getLength() == 0 )
194cdf0e10cSrcweir continue;
195cdf0e10cSrcweir sNode = sPrefix + it->first + sPostfix;
196cdf0e10cSrcweir OSL_TRACE("writing binding for: %s",::rtl::OUStringToOString(sNode , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
197cdf0e10cSrcweir seqValues[ 0 ].Name = sNode;
198cdf0e10cSrcweir seqValues[ 0 ].Value <<= it->second;
199cdf0e10cSrcweir //write the data to the registry
200cdf0e10cSrcweir SetSetProperties(SETNODE_BINDINGS,seqValues);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir //*****************************************************************************************************************
205cdf0e10cSrcweir // public method
206cdf0e10cSrcweir //*****************************************************************************************************************
EstablishFrameCallback(const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & xFrame)207cdf0e10cSrcweir void GlobalEventConfig_Impl::EstablishFrameCallback(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir // check if frame already exists inside list
210cdf0e10cSrcweir // ignore double registrations
211cdf0e10cSrcweir // every frame must be notified one times only!
212cdf0e10cSrcweir ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XFrame > xWeak(xFrame);
213cdf0e10cSrcweir FrameVector::const_iterator pIt = ::std::find(m_lFrames.begin(), m_lFrames.end(), xWeak);
214cdf0e10cSrcweir if (pIt == m_lFrames.end())
215cdf0e10cSrcweir m_lFrames.push_back(xWeak);
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir //*****************************************************************************************************************
219cdf0e10cSrcweir // private method
220cdf0e10cSrcweir //*****************************************************************************************************************
initBindingInfo()221cdf0e10cSrcweir void GlobalEventConfig_Impl::initBindingInfo()
222cdf0e10cSrcweir {
223cdf0e10cSrcweir // Get ALL names of current existing list items in configuration!
224cdf0e10cSrcweir Sequence< OUString > lEventNames = GetNodeNames( SETNODE_BINDINGS, utl::CONFIG_NAME_LOCAL_PATH );
225cdf0e10cSrcweir
226cdf0e10cSrcweir OUString aSetNode( SETNODE_BINDINGS );
227cdf0e10cSrcweir aSetNode += PATHDELIMITER;
228cdf0e10cSrcweir
229cdf0e10cSrcweir OUString aCommandKey( PATHDELIMITER );
230cdf0e10cSrcweir aCommandKey += PROPERTYNAME_BINDINGURL;
231cdf0e10cSrcweir
232cdf0e10cSrcweir // Expand all keys
233cdf0e10cSrcweir Sequence< OUString > lMacros(1);
234cdf0e10cSrcweir for (sal_Int32 i=0; i<lEventNames.getLength(); ++i )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir OUStringBuffer aBuffer( 32 );
237cdf0e10cSrcweir aBuffer.append( aSetNode );
238cdf0e10cSrcweir aBuffer.append( lEventNames[i] );
239cdf0e10cSrcweir aBuffer.append( aCommandKey );
240cdf0e10cSrcweir lMacros[0] = aBuffer.makeStringAndClear();
241cdf0e10cSrcweir OSL_TRACE("reading binding for: %s",::rtl::OUStringToOString(lMacros[0] , RTL_TEXTENCODING_ASCII_US ).pData->buffer);
242cdf0e10cSrcweir Sequence< Any > lValues = GetProperties( lMacros );
243cdf0e10cSrcweir OUString sMacroURL;
244cdf0e10cSrcweir if( lValues.getLength() > 0 )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir lValues[0] >>= sMacroURL;
247cdf0e10cSrcweir sal_Int32 startIndex = lEventNames[i].indexOf('\'');
248cdf0e10cSrcweir sal_Int32 endIndex = lEventNames[i].lastIndexOf('\'');
249cdf0e10cSrcweir if( startIndex >=0 && endIndex > 0 )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir startIndex++;
252cdf0e10cSrcweir OUString eventName = lEventNames[i].copy(startIndex,endIndex-startIndex);
253cdf0e10cSrcweir m_eventBindingHash[ eventName ] = sMacroURL;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir }
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
getEvents()259cdf0e10cSrcweir Reference< container::XNameReplace > SAL_CALL GlobalEventConfig_Impl::getEvents() throw (::com::sun::star::uno::RuntimeException)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir //how to return this object as an XNameReplace?
262cdf0e10cSrcweir Reference< container::XNameReplace > ret;
263cdf0e10cSrcweir return ret;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
replaceByName(const OUString & aName,const Any & aElement)266cdf0e10cSrcweir void SAL_CALL GlobalEventConfig_Impl::replaceByName( const OUString& aName, const Any& aElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir Sequence< beans::PropertyValue > props;
269cdf0e10cSrcweir //DF should we prepopulate the hash with a list of valid event Names?
270cdf0e10cSrcweir if( sal_False == ( aElement >>= props ) )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir throw lang::IllegalArgumentException( OUString(),
273cdf0e10cSrcweir Reference< XInterface > (), 2);
274cdf0e10cSrcweir }
275cdf0e10cSrcweir OUString macroURL;
276cdf0e10cSrcweir sal_Int32 nPropCount = props.getLength();
277cdf0e10cSrcweir for( sal_Int32 index = 0 ; index < nPropCount ; ++index )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir if ( props[ index ].Name.compareToAscii( "Script" ) == 0 )
280cdf0e10cSrcweir props[ index ].Value >>= macroURL;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir m_eventBindingHash[ aName ] = macroURL;
283cdf0e10cSrcweir SetModified();
284cdf0e10cSrcweir }
285cdf0e10cSrcweir
getByName(const OUString & aName)286cdf0e10cSrcweir Any SAL_CALL GlobalEventConfig_Impl::getByName( const OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir Any aRet;
289cdf0e10cSrcweir Sequence< beans::PropertyValue > props(2);
290cdf0e10cSrcweir props[0].Name = OUString::createFromAscii("EventType");
291cdf0e10cSrcweir props[0].Value <<= OUString::createFromAscii("Script");
292cdf0e10cSrcweir props[1].Name = OUString::createFromAscii("Script");
293cdf0e10cSrcweir EventBindingHash::const_iterator it = m_eventBindingHash.find( aName );
294cdf0e10cSrcweir if( it != m_eventBindingHash.end() )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir props[1].Value <<= it->second;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir else
299cdf0e10cSrcweir {
300cdf0e10cSrcweir // not yet accessed - is it a supported name?
301cdf0e10cSrcweir SupportedEventsVector::const_iterator pos = ::std::find(
302cdf0e10cSrcweir m_supportedEvents.begin(), m_supportedEvents.end(), aName );
303cdf0e10cSrcweir if ( pos == m_supportedEvents.end() )
304cdf0e10cSrcweir throw container::NoSuchElementException( aName, NULL );
305cdf0e10cSrcweir
306cdf0e10cSrcweir props[1].Value <<= OUString();
307cdf0e10cSrcweir }
308cdf0e10cSrcweir aRet <<= props;
309cdf0e10cSrcweir return aRet;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
getElementNames()312cdf0e10cSrcweir Sequence< OUString > SAL_CALL GlobalEventConfig_Impl::getElementNames( ) throw (RuntimeException)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir const ::rtl::OUString* pRet = m_supportedEvents.empty() ? NULL : &m_supportedEvents[0];
315cdf0e10cSrcweir return uno::Sequence< ::rtl::OUString >(pRet, m_supportedEvents.size());
316cdf0e10cSrcweir }
317cdf0e10cSrcweir
hasByName(const OUString & aName)318cdf0e10cSrcweir sal_Bool SAL_CALL GlobalEventConfig_Impl::hasByName( const OUString& aName ) throw (RuntimeException)
319cdf0e10cSrcweir {
320cdf0e10cSrcweir if ( m_eventBindingHash.find( aName ) != m_eventBindingHash.end() )
321cdf0e10cSrcweir return sal_True;
322cdf0e10cSrcweir
323cdf0e10cSrcweir // never accessed before - is it supported in general?
324cdf0e10cSrcweir SupportedEventsVector::const_iterator pos = ::std::find(
325cdf0e10cSrcweir m_supportedEvents.begin(), m_supportedEvents.end(), aName );
326cdf0e10cSrcweir if ( pos != m_supportedEvents.end() )
327cdf0e10cSrcweir return sal_True;
328cdf0e10cSrcweir
329cdf0e10cSrcweir return sal_False;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
getElementType()332cdf0e10cSrcweir Type SAL_CALL GlobalEventConfig_Impl::getElementType( ) throw (RuntimeException)
333cdf0e10cSrcweir {
334*86e1cf34SPedro Giffuni //DF definitely not sure about this??
335cdf0e10cSrcweir return ::getCppuType((const Sequence<beans::PropertyValue>*)0);
336cdf0e10cSrcweir }
337cdf0e10cSrcweir
hasElements()338cdf0e10cSrcweir sal_Bool SAL_CALL GlobalEventConfig_Impl::hasElements( ) throw (RuntimeException)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir return ( m_eventBindingHash.empty() );
341cdf0e10cSrcweir }
342cdf0e10cSrcweir
343cdf0e10cSrcweir // and now the wrapper
344cdf0e10cSrcweir
345cdf0e10cSrcweir
346cdf0e10cSrcweir //initialize static member
347cdf0e10cSrcweir GlobalEventConfig_Impl* GlobalEventConfig::m_pImpl = NULL ;
348cdf0e10cSrcweir sal_Int32 GlobalEventConfig::m_nRefCount = 0 ;
349cdf0e10cSrcweir
GlobalEventConfig()350cdf0e10cSrcweir GlobalEventConfig::GlobalEventConfig()
351cdf0e10cSrcweir {
352cdf0e10cSrcweir // Global access, must be guarded (multithreading!).
353cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
354cdf0e10cSrcweir // Increase our refcount ...
355cdf0e10cSrcweir ++m_nRefCount;
356cdf0e10cSrcweir // ... and initialize our data container only if it not already exist!
357cdf0e10cSrcweir if( m_pImpl == NULL )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir m_pImpl = new GlobalEventConfig_Impl;
360cdf0e10cSrcweir ItemHolder1::holdConfigItem(E_EVENTCFG);
361cdf0e10cSrcweir }
362cdf0e10cSrcweir }
363cdf0e10cSrcweir
~GlobalEventConfig()364cdf0e10cSrcweir GlobalEventConfig::~GlobalEventConfig()
365cdf0e10cSrcweir {
366cdf0e10cSrcweir // Global access, must be guarded (multithreading!)
367cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
368cdf0e10cSrcweir // Decrease our refcount.
369cdf0e10cSrcweir --m_nRefCount;
370cdf0e10cSrcweir // If last instance was deleted ...
371cdf0e10cSrcweir // we must destroy our static data container!
372cdf0e10cSrcweir if( m_nRefCount <= 0 )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir delete m_pImpl;
375cdf0e10cSrcweir m_pImpl = NULL;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
EstablishFrameCallback(const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & xFrame)379cdf0e10cSrcweir void GlobalEventConfig::EstablishFrameCallback(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame)
380cdf0e10cSrcweir {
381cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
382cdf0e10cSrcweir m_pImpl->EstablishFrameCallback( xFrame );
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
getEvents()385cdf0e10cSrcweir Reference< container::XNameReplace > SAL_CALL GlobalEventConfig::getEvents() throw (::com::sun::star::uno::RuntimeException)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
388cdf0e10cSrcweir Reference< container::XNameReplace > ret(this);
389cdf0e10cSrcweir return ret;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
replaceByName(const OUString & aName,const Any & aElement)392cdf0e10cSrcweir void SAL_CALL GlobalEventConfig::replaceByName( const OUString& aName, const Any& aElement ) throw (lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
395cdf0e10cSrcweir m_pImpl->replaceByName( aName, aElement );
396cdf0e10cSrcweir }
getByName(const OUString & aName)397cdf0e10cSrcweir Any SAL_CALL GlobalEventConfig::getByName( const OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
398cdf0e10cSrcweir {
399cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
400cdf0e10cSrcweir return m_pImpl->getByName( aName );
401cdf0e10cSrcweir }
getElementNames()402cdf0e10cSrcweir Sequence< OUString > SAL_CALL GlobalEventConfig::getElementNames( ) throw (RuntimeException)
403cdf0e10cSrcweir {
404cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
405cdf0e10cSrcweir return m_pImpl->getElementNames( );
406cdf0e10cSrcweir }
hasByName(const OUString & aName)407cdf0e10cSrcweir sal_Bool SAL_CALL GlobalEventConfig::hasByName( const OUString& aName ) throw (RuntimeException)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
410cdf0e10cSrcweir return m_pImpl->hasByName( aName );
411cdf0e10cSrcweir }
getElementType()412cdf0e10cSrcweir Type SAL_CALL GlobalEventConfig::getElementType( ) throw (RuntimeException)
413cdf0e10cSrcweir {
414cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
415cdf0e10cSrcweir return m_pImpl->getElementType( );
416cdf0e10cSrcweir }
hasElements()417cdf0e10cSrcweir sal_Bool SAL_CALL GlobalEventConfig::hasElements( ) throw (RuntimeException)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir MutexGuard aGuard( GetOwnStaticMutex() );
420cdf0e10cSrcweir return m_pImpl->hasElements( );
421cdf0e10cSrcweir }
422cdf0e10cSrcweir
GetOwnStaticMutex()423cdf0e10cSrcweir Mutex& GlobalEventConfig::GetOwnStaticMutex()
424cdf0e10cSrcweir {
425cdf0e10cSrcweir // Initialize static mutex only for one time!
426cdf0e10cSrcweir static Mutex* pMutex = NULL;
427cdf0e10cSrcweir // If these method first called (Mutex not already exist!) ...
428cdf0e10cSrcweir if( pMutex == NULL )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir // ... we must create a new one. Protect following code with
431cdf0e10cSrcweir // the global mutex -
432cdf0e10cSrcweir // It must be - we create a static variable!
433cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() );
434cdf0e10cSrcweir // We must check our pointer again - because it can be that
435cdf0e10cSrcweir // another instance of our class will be faster then these!
436cdf0e10cSrcweir if( pMutex == NULL )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir // Create the new mutex and set it for return on static variable.
439cdf0e10cSrcweir static Mutex aMutex;
440cdf0e10cSrcweir pMutex = &aMutex;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir }
443cdf0e10cSrcweir // Return new created or already existing mutex object.
444cdf0e10cSrcweir return *pMutex;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir
GetEventName(sal_Int32 nIndex)447cdf0e10cSrcweir ::rtl::OUString GlobalEventConfig::GetEventName( sal_Int32 nIndex )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir return GlobalEventConfig().m_pImpl->GetEventName( nIndex );
450cdf0e10cSrcweir }
451cdf0e10cSrcweir
452