Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / accessibility / AccessibleTextHelper.cxx
blobed98cd2967064e2ae685d9c7ff6fd76898721dad
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 #include <sal/config.h>
22 #include <memory>
24 #include <AccessibleTextHelper.hxx>
25 #include <DrawViewWrapper.hxx>
27 #include <vcl/svapp.hxx>
29 #include <svx/AccessibleTextHelper.hxx>
30 #include <svx/unoshtxt.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <vcl/window.hxx>
34 #include <com/sun/star/awt/XWindow.hpp>
35 #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 #include <osl/diagnose.h>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::accessibility;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Sequence;
44 namespace chart
47 AccessibleTextHelper::AccessibleTextHelper(
48 DrawViewWrapper * pDrawViewWrapper ) :
49 m_pDrawViewWrapper( pDrawViewWrapper )
52 AccessibleTextHelper::~AccessibleTextHelper()
56 void AccessibleTextHelper::initialize( const OUString& aCID,
57 const Reference< XAccessible >& xEventSource,
58 const Reference< awt::XWindow >& xWindow )
60 OSL_ENSURE( !aCID.isEmpty(), "Empty CID" );
61 OSL_ENSURE( xEventSource.is(), "Empty Event Source" );
62 OSL_ENSURE( xWindow.is(), "Empty Window" );
63 if( !xEventSource.is() || aCID.isEmpty() )
64 return;
66 SolarMutexGuard aSolarGuard;
68 m_pTextHelper.reset();
70 VclPtr<vcl::Window> pWindow( VCLUnoHelper::GetWindow( xWindow ));
71 if( pWindow )
73 SdrView * pView = m_pDrawViewWrapper;
74 if( pView )
76 SdrObject * pTextObj = m_pDrawViewWrapper->getNamedSdrObject( aCID );
77 if( pTextObj )
79 m_pTextHelper.reset( new ::accessibility::AccessibleTextHelper(std::make_unique<SvxTextEditSource>(*pTextObj, nullptr, *pView, *pWindow->GetOutDev())) );
80 m_pTextHelper->SetEventSource( xEventSource );
85 OSL_ENSURE( m_pTextHelper, "Couldn't create text helper" );
88 // ____ XAccessibleContext ____
89 sal_Int64 SAL_CALL AccessibleTextHelper::getAccessibleChildCount()
91 if( m_pTextHelper )
93 SolarMutexGuard aSolarGuard;
94 return m_pTextHelper->GetChildCount();
96 return 0;
99 Reference< XAccessible > SAL_CALL AccessibleTextHelper::getAccessibleChild( sal_Int64 i )
101 if( m_pTextHelper )
103 SolarMutexGuard aSolarGuard;
104 return m_pTextHelper->GetChild( i );
106 return Reference< XAccessible >();
109 Reference< XAccessible > SAL_CALL AccessibleTextHelper::getAccessibleParent()
111 OSL_FAIL( "Not implemented in this helper" );
112 return Reference< XAccessible >();
115 sal_Int64 SAL_CALL AccessibleTextHelper::getAccessibleIndexInParent()
117 OSL_FAIL( "Not implemented in this helper" );
118 return -1;
121 ::sal_Int16 SAL_CALL AccessibleTextHelper::getAccessibleRole()
123 OSL_FAIL( "Not implemented in this helper" );
124 return AccessibleRole::UNKNOWN;
127 OUString SAL_CALL AccessibleTextHelper::getAccessibleDescription()
129 OSL_FAIL( "Not implemented in this helper" );
130 return OUString();
133 OUString SAL_CALL AccessibleTextHelper::getAccessibleName()
135 OSL_FAIL( "Not implemented in this helper" );
136 return OUString();
139 Reference< XAccessibleRelationSet > SAL_CALL AccessibleTextHelper::getAccessibleRelationSet()
141 OSL_FAIL( "Not implemented in this helper" );
142 return Reference< XAccessibleRelationSet >();
145 sal_Int64 SAL_CALL AccessibleTextHelper::getAccessibleStateSet()
147 OSL_FAIL( "Not implemented in this helper" );
148 return 0;
151 lang::Locale SAL_CALL AccessibleTextHelper::getLocale()
153 OSL_FAIL( "Not implemented in this helper" );
154 return lang::Locale();
157 } // namespace chart
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */