tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / include / comphelper / accessiblecontexthelper.hxx
blob59a87a6987df36a5a7cd1b98438b92e750a6fa1a
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 #ifndef INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
21 #define INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
23 #include <comphelper/accessiblecomponenthelper.hxx>
24 #include <comphelper/solarmutex.hxx>
27 namespace comphelper
31 //= OContextEntryGuard
33 /** helper class for guarding the entry into OCommonAccessibleComponent methods.
35 <p>The class has two responsibilities:
36 <ul><li>it locks the mutex of an OCommonAccessibleComponent instance, as long as the guard lives</li>
37 <li>it checks if a given OCommonAccessibleComponent instance is alive, else an exception is thrown
38 our of the constructor of the guard</li>
39 </ul>
40 <br/>
41 This makes it your first choice (hopefully :) for guarding any interface method implementations of
42 you derived class.
43 </p>
45 class OContextEntryGuard : public ::osl::ClearableMutexGuard
47 public:
48 /** constructs the guard
50 <p>The given context (it's mutex, respectively) is locked, and an exception is thrown if the context
51 is not alive anymore. In the latter case, of course, the mutex is freed, again.</p>
53 @param _pContext
54 the context which shall be guarded
55 @precond <arg>_pContext</arg> != NULL
57 inline OContextEntryGuard( OCommonAccessibleComponent* _pContext );
61 inline OContextEntryGuard::OContextEntryGuard( OCommonAccessibleComponent* _pContext )
62 : ::osl::ClearableMutexGuard( _pContext->GetMutex() )
64 _pContext->ensureAlive();
68 //= OExternalLockGuard
70 class OExternalLockGuard
71 :public osl::Guard<SolarMutex>
72 ,public OContextEntryGuard
74 public:
75 inline OExternalLockGuard( OCommonAccessibleComponent* _pContext );
79 inline OExternalLockGuard::OExternalLockGuard( OCommonAccessibleComponent* _pContext )
80 :osl::Guard<SolarMutex>( SolarMutex::get() )
81 ,OContextEntryGuard( _pContext )
83 // Only lock the external mutex,
84 // release the ::osl::Mutex of the OCommonAccessibleComponent instance.
85 // If you call into another UNO object with locked ::osl::Mutex,
86 // this may lead to dead locks.
87 clear();
91 } // namespace comphelper
94 #endif // INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */