1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: current_context.hxx,v $
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 ************************************************************************/
30 #ifndef _UNO_CURRENT_CONTEXT_HXX_
31 #define _UNO_CURRENT_CONTEXT_HXX_
33 #include <uno/current_context.h>
35 #include <com/sun/star/uno/XCurrentContext.hpp>
47 /** Getting the current context.
49 Don't spread the returned interface around to other threads. Every thread has its own
52 @return current context or null ref, if none is set
54 inline Reference
< XCurrentContext
> SAL_CALL
getCurrentContext()
57 Reference
< XCurrentContext
> xRet
;
58 ::rtl::OUString
aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
59 ::uno_getCurrentContext( (void **)&xRet
, aEnvTypeName
.pData
, 0 );
62 /** Setting the current context.
64 @param xContext current context to be set
65 @return true, if context has been successfully set
67 inline bool SAL_CALL
setCurrentContext(
68 Reference
< XCurrentContext
> const & xContext
)
71 ::rtl::OUString
aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) );
72 return (::uno_setCurrentContext( xContext
.get(), aEnvTypeName
.pData
, 0 ) != sal_False
);
75 /** Objects of this class are used for applying a current context until they are destructed, i.e.
76 the ctor of this class saves the previous and sets the given context while the dtor restores
77 the previous one upon destruction.
81 /** this C++ environment type name.
84 ::rtl::OUString m_aEnvTypeName
;
88 Reference
< XCurrentContext
> m_xPreviousContext
;
91 /** Constructor: Saves the previous context and sets the new (given) one.
93 @param xNewContext new context to be set
96 Reference
< XCurrentContext
> const & xNewContext
= Reference
< XCurrentContext
>() )
98 /** Destructor: restores the previous context.
100 inline ~ContextLayer() SAL_THROW( () );
102 /** Gets the previously set context.
104 @return the previously set context
106 inline Reference
< XCurrentContext
> SAL_CALL
getPreviousContext() const
108 { return m_xPreviousContext
; }
110 //__________________________________________________________________________________________________
111 inline ContextLayer::ContextLayer( Reference
< XCurrentContext
> const & xNewContext
)
113 : m_aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME
) )
115 ::uno_getCurrentContext( (void **)&m_xPreviousContext
, m_aEnvTypeName
.pData
, 0 );
116 ::uno_setCurrentContext( xNewContext
.get(), m_aEnvTypeName
.pData
, 0 );
118 //__________________________________________________________________________________________________
119 inline ContextLayer::~ContextLayer()
122 ::uno_setCurrentContext( m_xPreviousContext
.get(), m_aEnvTypeName
.pData
, 0 );