Files
libreoffice/framework/source/dispatch/interceptionhelper.cxx

279 lines
12 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by: Armin Le Grand. #118558# Correcting OLE attributes of LO3.4 at load time by loading as OOo3.3, details see task. http://svn.apache.org/viewvc?view=revision&revision=1195906 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles http://svn.apache.org/viewvc?view=revision&revision=1293316 #119337# Solves the wrong get/setPropertyValue calls in SvxShapeText (and thus in SvxOle2Shape) http://svn.apache.org/viewvc?view=revision&revision=1344156 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117717#: remove wrong assertion http://svn.apache.org/viewvc?view=revision&revision=1172349 Patch contributed by Herbert Duerr goodbye Registration and License dialogs, don't let the door hit you http://svn.apache.org/viewvc?view=revision&revision=1172613 help gcc 4.6.0 on 32bit ubuntu 11.10" http://svn.apache.org/viewvc?view=revision&revision=1245357 Do not add targets for junit tests when junit is disabled. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1241508 Revert "sb140: #i117082# avoid unncessary static class data members commit 21d97438e2944861e26e4984195f959a0cce1e41. remove obsolete FreeBSD visibility special case. retain consolidated BSD bridge code, remove OS/2 pieces.
2012-11-12 17:21:24 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2001-07-02 12:27:02 +00:00
#include <dispatch/interceptionhelper.hxx>
#include <com/sun/star/frame/XInterceptorInfo.hpp>
#include <vcl/svapp.hxx>
namespace framework{
sal_Bool InterceptionHelper::m_bPreferrFirstInterceptor = sal_True;
InterceptionHelper::InterceptionHelper(const css::uno::Reference< css::frame::XFrame >& xOwner,
const css::uno::Reference< css::frame::XDispatchProvider >& xSlave)
: m_xOwnerWeak (xOwner )
, m_xSlave (xSlave )
2001-07-02 12:27:02 +00:00
{
}
InterceptionHelper::~InterceptionHelper()
{
}
css::uno::Reference< css::frame::XDispatch > SAL_CALL InterceptionHelper::queryDispatch(const css::util::URL& aURL ,
const OUString& sTargetFrameName,
sal_Int32 nSearchFlags )
throw(css::uno::RuntimeException, std::exception)
2001-07-02 12:27:02 +00:00
{
// SAFE {
SolarMutexClearableGuard aReadLock;
// a) first search an interceptor, which match to this URL by it's URL pattern registration
// Note: if it return NULL - it does not mean an empty interceptor list automaticly!
css::uno::Reference< css::frame::XDispatchProvider > xInterceptor;
InterceptorList::const_iterator pIt = m_lInterceptionRegs.findByPattern(aURL.Complete);
if (pIt != m_lInterceptionRegs.end())
xInterceptor = pIt->xInterceptor;
// b) No match by registration - but a valid interceptor list.
// Use first interceptor everytimes.
// Note: it doesn't matter, which direction this helper implementation use to ask interceptor objects.
// Using of member m_aInterceptorList will starts at the beginning everytimes.
// It depends from the filling operation, in which direction it works really!
if (!xInterceptor.is() && m_lInterceptionRegs.size()>0)
2001-07-02 12:27:02 +00:00
{
pIt = m_lInterceptionRegs.begin();
xInterceptor = pIt->xInterceptor;
2001-07-02 12:27:02 +00:00
}
// c) No registered interceptor => use our direct slave.
// This helper exist by design and must be valid everytimes ...
// But to be more feature proof - we should check that .-)
if (!xInterceptor.is() && m_xSlave.is())
xInterceptor = m_xSlave;
aReadLock.clear();
// } SAFE
css::uno::Reference< css::frame::XDispatch > xReturn;
if (xInterceptor.is())
xReturn = xInterceptor->queryDispatch(aURL, sTargetFrameName, nSearchFlags);
2001-07-02 12:27:02 +00:00
return xReturn;
}
css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL InterceptionHelper::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor )
throw(css::uno::RuntimeException, std::exception)
2001-07-02 12:27:02 +00:00
{
sal_Int32 c = lDescriptor.getLength();
css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatches (c);
css::uno::Reference< css::frame::XDispatch >* pDispatches = lDispatches.getArray();
const css::frame::DispatchDescriptor* pDescriptor = lDescriptor.getConstArray();
2001-07-02 12:27:02 +00:00
for (sal_Int32 i=0; i<c; ++i)
pDispatches[i] = queryDispatch(pDescriptor[i].FeatureURL, pDescriptor[i].FrameName, pDescriptor[i].SearchFlags);
2001-07-02 12:27:02 +00:00
return lDispatches;
2001-07-02 12:27:02 +00:00
}
void SAL_CALL InterceptionHelper::registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor)
throw(css::uno::RuntimeException, std::exception)
2001-07-02 12:27:02 +00:00
{
// reject wrong calling of this interface method
css::uno::Reference< css::frame::XDispatchProvider > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
if (!xInterceptor.is())
throw css::uno::RuntimeException("NULL references not allowed as in parameter", xThis);
2001-07-02 12:27:02 +00:00
// Fill a new info structure for new interceptor.
// Save his reference and try to get an additional URL/pattern list from him.
// If no list exist register these interceptor for all dispatch events with "*"!
InterceptorInfo aInfo;
aInfo.xInterceptor = css::uno::Reference< css::frame::XDispatchProvider >(xInterceptor, css::uno::UNO_QUERY);
css::uno::Reference< css::frame::XInterceptorInfo > xInfo(xInterceptor, css::uno::UNO_QUERY);
if (xInfo.is())
aInfo.lURLPattern = xInfo->getInterceptedURLs();
2001-07-02 12:27:02 +00:00
else
{
aInfo.lURLPattern.realloc(1);
aInfo.lURLPattern[0] = "*";
2001-07-02 12:27:02 +00:00
}
// SAFE {
SolarMutexClearableGuard aWriteLock;
// a) no interceptor at all - set this instance as master for given interceptor
// and set our slave as it's slave - and put this interceptor to the list.
// It's place there doesn matter. Because this list is currently empty.
CWS-TOOLING: integrate CWS oj18 2009-08-21 15:08:49 +0200 oj r275263 : wrong check 2009-08-21 08:56:01 +0200 oj r275215 : missing not 2009-08-20 07:27:13 +0200 oj r275164 : use new method from global 2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale 2009-08-18 10:39:32 +0200 oj r275082 : missing header include 2009-08-18 10:09:44 +0200 oj r275081 : new methods at global 2009-08-18 10:09:00 +0200 oj r275080 : unused var 2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml 2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55) 2009-08-17 13:29:44 +0200 oj r275047 : compile error 2009-08-17 13:27:47 +0200 oj r275045 : compile error 2009-08-17 11:44:54 +0200 oj r275040 : add dep 2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl 2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl 2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code 2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand 2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char 2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator 2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc 2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled 2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger 2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand 2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand 2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl 2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
2009-09-08 04:57:32 +00:00
if (m_lInterceptionRegs.empty())
2001-07-02 12:27:02 +00:00
{
xInterceptor->setMasterDispatchProvider(xThis );
xInterceptor->setSlaveDispatchProvider (m_xSlave);
m_lInterceptionRegs.push_back(aInfo);
2001-07-02 12:27:02 +00:00
}
// b) OK - there is at least one interceptor already registered.
// It's slave and it's master must be valid references ...
// because we created it. But we have to look for the static bool which
// regulate direction of using of interceptor objects!
// b1) If "m_bPreferrFirstInterceptor" is set to true, we have to
// insert it behind any other existing interceptor - means at the end of our list.
else if (m_bPreferrFirstInterceptor)
2001-07-02 12:27:02 +00:00
{
css::uno::Reference< css::frame::XDispatchProvider > xMasterD = m_lInterceptionRegs.rbegin()->xInterceptor;
css::uno::Reference< css::frame::XDispatchProviderInterceptor > xMasterI (xMasterD, css::uno::UNO_QUERY);
2001-07-02 12:27:02 +00:00
xInterceptor->setMasterDispatchProvider(xMasterD );
xInterceptor->setSlaveDispatchProvider (m_xSlave );
xMasterI->setSlaveDispatchProvider (aInfo.xInterceptor);
2001-07-02 12:27:02 +00:00
m_lInterceptionRegs.push_back(aInfo);
}
2001-07-02 12:27:02 +00:00
// b2) If "m_bPreferrFirstInterceptor" is set to false, we have to
// insert it before any other existing interceptor - means at the beginning of our list.
else
2001-07-02 12:27:02 +00:00
{
css::uno::Reference< css::frame::XDispatchProvider > xSlaveD = m_lInterceptionRegs.begin()->xInterceptor;
css::uno::Reference< css::frame::XDispatchProviderInterceptor > xSlaveI (xSlaveD , css::uno::UNO_QUERY);
xInterceptor->setMasterDispatchProvider(xThis );
xInterceptor->setSlaveDispatchProvider (xSlaveD );
xSlaveI->setMasterDispatchProvider (aInfo.xInterceptor);
m_lInterceptionRegs.push_front(aInfo);
2001-07-02 12:27:02 +00:00
}
css::uno::Reference< css::frame::XFrame > xOwner(m_xOwnerWeak.get(), css::uno::UNO_QUERY);
aWriteLock.clear();
// } SAFE
// Don't forget to send a frame action event "context changed".
// Any cached dispatch objects must be validated now!
if (xOwner.is())
2001-07-02 12:27:02 +00:00
xOwner->contextChanged();
}
void SAL_CALL InterceptionHelper::releaseDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor)
throw(css::uno::RuntimeException, std::exception)
2001-07-02 12:27:02 +00:00
{
// reject wrong calling of this interface method
css::uno::Reference< css::frame::XDispatchProvider > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
if (!xInterceptor.is())
throw css::uno::RuntimeException("NULL references not allowed as in parameter", xThis);
// SAFE {
SolarMutexClearableGuard aWriteLock;
// search this interceptor ...
// If it could be located inside cache -
// use it's slave/master relations to update the interception list;
// set empty references for it as new master and slave;
// and relase it from out cache.
InterceptorList::iterator pIt = m_lInterceptionRegs.findByReference(xInterceptor);
if (pIt != m_lInterceptionRegs.end())
2001-07-02 12:27:02 +00:00
{
css::uno::Reference< css::frame::XDispatchProvider > xSlaveD (xInterceptor->getSlaveDispatchProvider() , css::uno::UNO_QUERY);
css::uno::Reference< css::frame::XDispatchProvider > xMasterD (xInterceptor->getMasterDispatchProvider(), css::uno::UNO_QUERY);
css::uno::Reference< css::frame::XDispatchProviderInterceptor > xSlaveI (xSlaveD , css::uno::UNO_QUERY);
css::uno::Reference< css::frame::XDispatchProviderInterceptor > xMasterI (xMasterD , css::uno::UNO_QUERY);
2001-07-02 12:27:02 +00:00
if (xMasterI.is())
xMasterI->setSlaveDispatchProvider(xSlaveD);
2001-07-02 12:27:02 +00:00
if (xSlaveI.is())
xSlaveI->setMasterDispatchProvider(xMasterD);
2001-07-02 12:27:02 +00:00
xInterceptor->setSlaveDispatchProvider (css::uno::Reference< css::frame::XDispatchProvider >());
xInterceptor->setMasterDispatchProvider(css::uno::Reference< css::frame::XDispatchProvider >());
2001-07-02 12:27:02 +00:00
m_lInterceptionRegs.erase(pIt);
2001-07-02 12:27:02 +00:00
}
css::uno::Reference< css::frame::XFrame > xOwner(m_xOwnerWeak.get(), css::uno::UNO_QUERY);
2001-07-02 12:27:02 +00:00
aWriteLock.clear();
// } SAFE
2001-07-02 12:27:02 +00:00
// Don't forget to send a frame action event "context changed".
// Any cached dispatch objects must be validated now!
if (xOwner.is())
xOwner->contextChanged();
2001-07-02 12:27:02 +00:00
}
#define FORCE_DESTRUCTION_OF_INTERCEPTION_CHAIN
void SAL_CALL InterceptionHelper::disposing(const css::lang::EventObject& aEvent)
throw(css::uno::RuntimeException, std::exception)
2001-07-02 12:27:02 +00:00
{
#ifdef FORCE_DESTRUCTION_OF_INTERCEPTION_CHAIN
// SAFE ->
SolarMutexResettableGuard aReadLock;
// check calli ... we accept such disposing call's only from our onwer frame.
css::uno::Reference< css::frame::XFrame > xOwner(m_xOwnerWeak.get(), css::uno::UNO_QUERY);
if (aEvent.Source != xOwner)
return;
// Because every interceptor hold at least one reference to us ... and we destruct this list
// of interception objects ... we should hold ourself alive .-)
css::uno::Reference< css::frame::XDispatchProvider > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY_THROW);
// We need a full copy of all currently registered interceptor objects.
// Otherwhise we cant iterate over this vector without the risk, that our iterator will be invalid.
// Because this vetor will be influenced by every deregistered interceptor.
InterceptionHelper::InterceptorList aCopy = m_lInterceptionRegs;
aReadLock.clear();
// <- SAFE
InterceptionHelper::InterceptorList::iterator pIt;
for ( pIt = aCopy.begin();
pIt != aCopy.end();
++pIt )
{
InterceptionHelper::InterceptorInfo& rInfo = *pIt;
if (rInfo.xInterceptor.is())
{
css::uno::Reference< css::frame::XDispatchProviderInterceptor > xInterceptor(rInfo.xInterceptor, css::uno::UNO_QUERY_THROW);
releaseDispatchProviderInterceptor(xInterceptor);
rInfo.xInterceptor.clear();
}
}
aCopy.clear();
#if OSL_DEBUG_LEVEL > 0
// SAFE ->
aReadLock.reset();
CWS-TOOLING: integrate CWS oj18 2009-08-21 15:08:49 +0200 oj r275263 : wrong check 2009-08-21 08:56:01 +0200 oj r275215 : missing not 2009-08-20 07:27:13 +0200 oj r275164 : use new method from global 2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale 2009-08-18 10:39:32 +0200 oj r275082 : missing header include 2009-08-18 10:09:44 +0200 oj r275081 : new methods at global 2009-08-18 10:09:00 +0200 oj r275080 : unused var 2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml 2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55) 2009-08-17 13:29:44 +0200 oj r275047 : compile error 2009-08-17 13:27:47 +0200 oj r275045 : compile error 2009-08-17 11:44:54 +0200 oj r275040 : add dep 2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl 2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl 2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code 2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand 2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char 2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator 2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc 2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled 2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger 2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand 2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand 2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl 2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
2009-09-08 04:57:32 +00:00
if (!m_lInterceptionRegs.empty() )
OSL_FAIL("There are some pending interceptor objects, which seems to be registered during (!) the destruction of a frame.");
aReadLock.clear();
// <- SAFE
#endif // ODL_DEBUG_LEVEL>0
#endif // FORCE_DESTRUCTION_OF_INTERCEPTION_CHAIN
2001-07-02 12:27:02 +00:00
}
} // namespace framework
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */