merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / misc / configinteractionhandler.cxx
bloba1b48777e2a6c928646134eaa1a882b6577c983b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: configinteractionhandler.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
34 #include "sal/config.h"
36 #include "configinteractionhandler.hxx"
38 #include "com/sun/star/task/XInteractionHandler.hpp"
39 #include "com/sun/star/uno/Any.hxx"
40 #include "com/sun/star/uno/Reference.hxx"
41 #include "com/sun/star/uno/RuntimeException.hpp"
42 #include "com/sun/star/uno/XCurrentContext.hpp"
43 #include "cppuhelper/implbase1.hxx"
44 #include "rtl/string.h"
45 #include "rtl/ustring.h"
46 #include "rtl/ustring.hxx"
47 #include "uno/current_context.hxx"
49 namespace {
51 namespace css = com::sun::star;
53 static char const INTERACTION_HANDLER[] = "configuration.interaction-handler";
57 namespace configmgr { namespace apihelper {
59 class ConfigurationInteractionHandler::Context:
60 public cppu::WeakImplHelper1< css::uno::XCurrentContext >
62 public:
63 explicit Context(ConfigurationInteractionHandler * parent):
64 m_parent(parent) {}
66 virtual css::uno::Any SAL_CALL getValueByName(rtl::OUString const & name)
67 throw (css::uno::RuntimeException)
69 return
70 name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(INTERACTION_HANDLER))
71 ? m_handler : m_parent->getPreviousContextValue(name);
74 void setInteractionHandler(
75 css::uno::Reference< css::task::XInteractionHandler > const & handler)
76 { m_handler <<= handler; }
78 private:
79 Context(Context &); // not defined
80 void operator =(Context &); // not defined
82 virtual ~Context() {}
84 ConfigurationInteractionHandler * m_parent;
85 css::uno::Any m_handler;
88 ConfigurationInteractionHandler::ConfigurationInteractionHandler():
89 m_context(new Context(this)), m_layer(m_context.get()) {}
91 ConfigurationInteractionHandler::~ConfigurationInteractionHandler() {}
93 css::uno::Reference< css::task::XInteractionHandler >
94 ConfigurationInteractionHandler::get() const {
95 return css::uno::Reference< css::task::XInteractionHandler >(
96 getPreviousContextValue(
97 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(INTERACTION_HANDLER))),
98 css::uno::UNO_QUERY);
101 void ConfigurationInteractionHandler::setRecursive(
102 css::uno::Reference< css::task::XInteractionHandler > const & handler)
104 m_context->setInteractionHandler(handler);
107 css::uno::Any ConfigurationInteractionHandler::getPreviousContextValue(
108 rtl::OUString const & name) const
110 css::uno::Reference< css::uno::XCurrentContext > c(
111 m_layer.getPreviousContext());
112 return c.is() ? c->getValueByName(name) : css::uno::Any();