LibreOffice
LibreOffice 4.2 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
current_context.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_UNO_CURRENT_CONTEXT_HXX
20 #define INCLUDED_UNO_CURRENT_CONTEXT_HXX
21 
22 #include <uno/current_context.h>
23 
24 #include <com/sun/star/uno/XCurrentContext.hpp>
25 
26 
27 namespace com
28 {
29 namespace sun
30 {
31 namespace star
32 {
33 namespace uno
34 {
35 
44  SAL_THROW(())
45 {
47  ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME );
48  ::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 );
49  return xRet;
50 }
56 inline bool SAL_CALL setCurrentContext(
57  Reference< XCurrentContext > const & xContext )
58  SAL_THROW(())
59 {
60  ::rtl::OUString aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME );
61  return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False);
62 }
63 
69 {
72  ::rtl::OUString m_aEnvTypeName;
75  Reference< XCurrentContext > m_xPreviousContext;
76 
77 public:
82  inline ContextLayer(
84  SAL_THROW(());
87  inline ~ContextLayer() SAL_THROW(());
88 
94  SAL_THROW(())
95  { return m_xPreviousContext; }
96 };
97 //__________________________________________________________________________________________________
99  SAL_THROW(())
100  : m_aEnvTypeName( CPPU_CURRENT_LANGUAGE_BINDING_NAME )
101 {
102  ::uno_getCurrentContext( (void **)&m_xPreviousContext, m_aEnvTypeName.pData, 0 );
103  ::uno_setCurrentContext( xNewContext.get(), m_aEnvTypeName.pData, 0 );
104 }
105 //__________________________________________________________________________________________________
107  SAL_THROW(())
108 {
109  ::uno_setCurrentContext( m_xPreviousContext.get(), m_aEnvTypeName.pData, 0 );
110 }
111 
112 }
113 }
114 }
115 }
116 
117 #endif
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
~ContextLayer()
Destructor: restores the previous context.
Definition: current_context.hxx:106
CPPU_DLLPUBLIC sal_Bool uno_getCurrentContext(void **ppCurrentContext, rtl_uString *pEnvDcp, void *pEnvContext) SAL_THROW_EXTERN_C()
Gets the current task's context.
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:82
interface_type * get() const
Gets interface pointer.
Definition: Reference.h:411
CPPU_DLLPUBLIC sal_Bool uno_setCurrentContext(void *pCurrentContext, rtl_uString *pEnvDcp, void *pEnvContext) SAL_THROW_EXTERN_C()
Sets the current task's context.
Reference< XCurrentContext > getPreviousContext() const
Gets the previously set context.
Definition: current_context.hxx:93
ContextLayer(Reference< XCurrentContext > const &xNewContext=Reference< XCurrentContext >())
Constructor: Saves the previous context and sets the new (given) one.
Definition: current_context.hxx:98
Reference< XCurrentContext > getCurrentContext()
Getting the current context.
Definition: current_context.hxx:43
bool setCurrentContext(Reference< XCurrentContext > const &xContext)
Setting the current context.
Definition: current_context.hxx:56
Objects of this class are used for applying a current context until they are destructed, i.e.
Definition: current_context.hxx:68
#define sal_False
Definition: types.h:47
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:358