GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / desktop / source / app / configinit.cxx
blob11ee1f858f1bf43535e0abd8c7fdf82ff5e5cd9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "configinit.hxx"
22 #include "desktop.hrc"
23 #include "app.hxx"
24 #include <comphelper/processfactory.hxx>
25 #include <uno/current_context.hxx>
26 #include <cppuhelper/implbase1.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <osl/diagnose.h>
29 #include <stdio.h>
30 #include <com/sun/star/task/InteractionHandler.hpp>
32 // ----------------------------------------------------------------------------
34 namespace uno = ::com::sun::star::uno;
35 namespace lang = ::com::sun::star::lang;
36 using uno::UNO_QUERY;
38 // ----------------------------------------------------------------------------
40 // must be aligned with configmgr/source/misc/configinteractionhandler
41 static char const CONFIG_ERROR_HANDLER[] = "configuration.interaction-handler";
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
45 // ConfigurationErrorHandler
46 // ----------------------------------------------------------------------------
48 namespace
50 typedef uno::Reference< uno::XCurrentContext > CurrentContext;
51 class SimpleCurrentContext : public cppu::WeakImplHelper1< uno::XCurrentContext >
53 CurrentContext m_xChainedContext;
54 public:
55 explicit
56 SimpleCurrentContext(const CurrentContext & xChainedContext)
57 : m_xChainedContext(xChainedContext)
60 void install() { uno::setCurrentContext(this); }
61 void deinstall() { uno::setCurrentContext(m_xChainedContext); }
63 uno::Any getChainedValueByName( OUString const & aName) const
65 return m_xChainedContext.is()
66 ? m_xChainedContext->getValueByName(aName)
67 : uno::Any();
70 // XCurrentContext
71 virtual uno::Any SAL_CALL
72 getValueByName( OUString const & aName)
73 throw (uno::RuntimeException);
76 uno::Any SAL_CALL
77 SimpleCurrentContext::getValueByName( OUString const & aName)
78 throw (uno::RuntimeException)
80 return getChainedValueByName(aName);
85 // ----------------------------------------------------------------------------
86 class ConfigurationErrorHandler::Context : public SimpleCurrentContext
88 public:
89 Context()
90 : SimpleCurrentContext( uno::getCurrentContext() )
94 ~Context()
98 // XCurrentContext
99 virtual uno::Any SAL_CALL
100 getValueByName( OUString const & aName)
101 throw (uno::RuntimeException);
103 private:
104 InteractionHandler m_xHandler;
107 //------------------------------------------------------------------------------
108 uno::Any SAL_CALL ConfigurationErrorHandler::Context::getValueByName( OUString const & aName)
109 throw (uno::RuntimeException)
111 if ( aName == CONFIG_ERROR_HANDLER )
113 if ( !m_xHandler.is() )
114 m_xHandler = ConfigurationErrorHandler::getDefaultInteractionHandler();
115 return uno::Any( m_xHandler );
117 return SimpleCurrentContext::getValueByName( aName );
120 //------------------------------------------------------------------------------
121 ConfigurationErrorHandler::~ConfigurationErrorHandler()
123 deactivate();
126 //------------------------------------------------------------------------------
127 /// installs the handler into the current context
128 void ConfigurationErrorHandler::activate()
130 if (!m_pContext)
132 m_pContext = new Context;
133 m_pContext->acquire();
135 m_pContext->install();
138 //------------------------------------------------------------------------------
139 /// deinstalls the handler from the current context, restoring the previous context
140 void ConfigurationErrorHandler::deactivate()
142 if (m_pContext)
144 m_pContext->deinstall();
145 m_pContext->release();
146 m_pContext = 0;
149 //------------------------------------------------------------------------------
151 ConfigurationErrorHandler::InteractionHandler ConfigurationErrorHandler::getDefaultInteractionHandler()
153 uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
154 InteractionHandler xHandler( com::sun::star::task::InteractionHandler::createWithParent(xContext, 0), UNO_QUERY );
155 return xHandler;
157 //------------------------------------------------------------------------------
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */