Files
libreoffice/cppu/inc/uno/current_context.hxx

129 lines
4.1 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-12-21 13:33:52 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-12-21 13:33:52 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-12-21 13:33:52 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-12-21 13:33:52 +00:00
*
* This file is part of OpenOffice.org.
2000-12-21 13:33:52 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-12-21 13:33:52 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-12-21 13:33:52 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-12-21 13:33:52 +00:00
*
************************************************************************/
#ifndef _UNO_CURRENT_CONTEXT_HXX_
#define _UNO_CURRENT_CONTEXT_HXX_
#include <uno/current_context.h>
#include <com/sun/star/uno/XCurrentContext.hpp>
namespace com
{
namespace sun
{
namespace star
{
namespace uno
{
2001-05-07 14:07:01 +00:00
/** Getting the current context.
2001-11-09 08:14:31 +00:00
@attention
Don't spread the returned interface around to other threads. Every thread has its own
current context.
2001-05-07 14:07:01 +00:00
@return current context or null ref, if none is set
2000-12-21 13:33:52 +00:00
*/
2001-05-07 14:07:01 +00:00
inline Reference< XCurrentContext > SAL_CALL getCurrentContext()
2012-01-26 16:00:09 +01:00
SAL_THROW(())
2000-12-21 13:33:52 +00:00
{
Reference< XCurrentContext > xRet;
2001-05-07 14:07:01 +00:00
::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
2000-12-21 13:33:52 +00:00
::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 );
return xRet;
}
2001-05-07 14:07:01 +00:00
/** Setting the current context.
2000-12-21 13:33:52 +00:00
2001-05-07 14:07:01 +00:00
@param xContext current context to be set
@return true, if context has been successfully set
2000-12-21 13:33:52 +00:00
*/
2001-05-07 14:07:01 +00:00
inline bool SAL_CALL setCurrentContext(
Reference< XCurrentContext > const & xContext )
2012-01-26 16:00:09 +01:00
SAL_THROW(())
2000-12-21 13:33:52 +00:00
{
2001-05-07 14:07:01 +00:00
::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False);
2000-12-21 13:33:52 +00:00
}
2001-11-09 08:14:31 +00:00
/** Objects of this class are used for applying a current context until they are destructed, i.e.
the ctor of this class saves the previous and sets the given context while the dtor restores
the previous one upon destruction.
2001-08-22 08:33:01 +00:00
*/
class ContextLayer
{
2001-11-09 08:14:31 +00:00
/** this C++ environment type name.
*/
::rtl::OUString m_aEnvTypeName;
2001-08-22 08:33:01 +00:00
/** previous context
*/
Reference< XCurrentContext > m_xPreviousContext;
public:
/** Constructor: Saves the previous context and sets the new (given) one.
@param xNewContext new context to be set
*/
inline ContextLayer(
Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() )
2012-01-26 16:00:09 +01:00
SAL_THROW(());
2001-08-22 08:33:01 +00:00
/** Destructor: restores the previous context.
*/
2012-01-26 16:00:09 +01:00
inline ~ContextLayer() SAL_THROW(());
2001-08-22 08:33:01 +00:00
/** Gets the previously set context.
@return the previously set context
*/
inline Reference< XCurrentContext > SAL_CALL getPreviousContext() const
2012-01-26 16:00:09 +01:00
SAL_THROW(())
2001-08-22 08:33:01 +00:00
{ return m_xPreviousContext; }
};
//__________________________________________________________________________________________________
inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext )
2012-01-26 16:00:09 +01:00
SAL_THROW(())
2001-11-09 08:14:31 +00:00
: m_aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) )
2001-08-22 08:33:01 +00:00
{
2001-11-09 08:14:31 +00:00
::uno_getCurrentContext( (void **)&m_xPreviousContext, m_aEnvTypeName.pData, 0 );
::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, 0 );
2001-08-22 08:33:01 +00:00
}
//__________________________________________________________________________________________________
inline ContextLayer::~ContextLayer()
2012-01-26 16:00:09 +01:00
SAL_THROW(())
2001-08-22 08:33:01 +00:00
{
2001-11-09 08:14:31 +00:00
::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, 0 );
2001-08-22 08:33:01 +00:00
}
2000-12-21 13:33:52 +00:00
}
}
}
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */