UDK 3.2.7 C/C++ API Reference
uno/current_context.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 #ifndef _UNO_CURRENT_CONTEXT_HXX_
00029 #define _UNO_CURRENT_CONTEXT_HXX_
00030 
00031 #include <uno/current_context.h>
00032 
00033 #include <com/sun/star/uno/XCurrentContext.hpp>
00034 
00035 
00036 namespace com
00037 {
00038 namespace sun
00039 {
00040 namespace star
00041 {
00042 namespace uno
00043 {
00044 
00052 inline Reference< XCurrentContext > SAL_CALL getCurrentContext()
00053     SAL_THROW(())
00054 {
00055     Reference< XCurrentContext > xRet;
00056     ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
00057     ::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 );
00058     return xRet;
00059 }
00065 inline bool SAL_CALL setCurrentContext(
00066     Reference< XCurrentContext > const & xContext )
00067     SAL_THROW(())
00068 {
00069     ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
00070     return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False);
00071 }
00072 
00077 class ContextLayer
00078 {
00081     ::rtl::OUString m_aEnvTypeName;
00084     Reference< XCurrentContext > m_xPreviousContext;
00085 
00086 public:
00091     inline ContextLayer(
00092         Reference< XCurrentContext > const & xNewContext = Reference< XCurrentContext >() )
00093         SAL_THROW(());
00096     inline ~ContextLayer() SAL_THROW(());
00097 
00102     inline Reference< XCurrentContext > SAL_CALL getPreviousContext() const
00103         SAL_THROW(())
00104         { return m_xPreviousContext; }
00105 };
00106 //__________________________________________________________________________________________________
00107 inline ContextLayer::ContextLayer( Reference< XCurrentContext > const & xNewContext )
00108     SAL_THROW(())
00109     : m_aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) )
00110 {
00111     ::uno_getCurrentContext( (void **)&m_xPreviousContext, m_aEnvTypeName.pData, 0 );
00112     ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, 0 );
00113 }
00114 //__________________________________________________________________________________________________
00115 inline ContextLayer::~ContextLayer()
00116     SAL_THROW(())
00117 {
00118     ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, 0 );
00119 }
00120 
00121 }
00122 }
00123 }
00124 }
00125 
00126 #endif
00127 
00128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines