lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / svx / source / accessibility / AccessibleGraphicShape.cxx
bloba688a8a0995f1e8cb04a5ca47db0da4d65165185
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 <svx/AccessibleGraphicShape.hxx>
22 #include <svx/ShapeTypeHandler.hxx>
23 #include <svx/SvxShapeTypes.hxx>
24 #include <svx/svdobj.hxx>
25 #include <svx/svdmodel.hxx>
27 #include <cppuhelper/queryinterface.hxx>
29 using namespace ::accessibility;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::accessibility;
33 // internal
34 AccessibleGraphicShape::AccessibleGraphicShape (
35 const AccessibleShapeInfo& rShapeInfo,
36 const AccessibleShapeTreeInfo& rShapeTreeInfo)
37 : AccessibleShape (rShapeInfo, rShapeTreeInfo)
44 AccessibleGraphicShape::~AccessibleGraphicShape()
48 // XAccessibleImage
49 OUString SAL_CALL AccessibleGraphicShape::getAccessibleImageDescription()
50 throw (::com::sun::star::uno::RuntimeException, std::exception)
52 if (m_pShape)
53 return m_pShape->GetTitle();
54 return AccessibleShape::getAccessibleDescription ();
60 sal_Int32 SAL_CALL AccessibleGraphicShape::getAccessibleImageHeight()
61 throw (::com::sun::star::uno::RuntimeException, std::exception)
63 return AccessibleShape::getSize().Height;
69 sal_Int32 SAL_CALL AccessibleGraphicShape::getAccessibleImageWidth()
70 throw (::com::sun::star::uno::RuntimeException, std::exception)
72 return AccessibleShape::getSize().Width;
75 // XInterface
76 com::sun::star::uno::Any SAL_CALL
77 AccessibleGraphicShape::queryInterface (const com::sun::star::uno::Type & rType)
78 throw (::com::sun::star::uno::RuntimeException, std::exception)
80 ::com::sun::star::uno::Any aReturn = AccessibleShape::queryInterface (rType);
81 if ( ! aReturn.hasValue())
82 aReturn = ::cppu::queryInterface (rType,
83 static_cast<XAccessibleImage*>(this));
84 return aReturn;
89 void SAL_CALL
90 AccessibleGraphicShape::acquire()
91 throw ()
93 AccessibleShape::acquire ();
98 void SAL_CALL
99 AccessibleGraphicShape::release()
100 throw ()
102 AccessibleShape::release ();
105 // XServiceInfo
106 OUString SAL_CALL
107 AccessibleGraphicShape::getImplementationName()
108 throw (::com::sun::star::uno::RuntimeException, std::exception)
110 return OUString("AccessibleGraphicShape");
116 ::com::sun::star::uno::Sequence< OUString> SAL_CALL
117 AccessibleGraphicShape::getSupportedServiceNames()
118 throw (::com::sun::star::uno::RuntimeException, std::exception)
120 ThrowIfDisposed ();
121 // Get list of supported service names from base class...
122 uno::Sequence<OUString> aServiceNames =
123 AccessibleShape::getSupportedServiceNames();
124 sal_Int32 nCount (aServiceNames.getLength());
126 // ...and add additional names.
127 aServiceNames.realloc (nCount + 1);
128 aServiceNames[nCount] = "com.sun.star.drawing.AccessibleGraphicShape";
130 return aServiceNames;
133 // XTypeProvider
134 uno::Sequence<uno::Type> SAL_CALL
135 AccessibleGraphicShape::getTypes()
136 throw (uno::RuntimeException, std::exception)
138 // Get list of types from the context base implementation...
139 uno::Sequence<uno::Type> aTypeList (AccessibleShape::getTypes());
140 // ...and add the additional type for the component.
141 long nTypeCount = aTypeList.getLength();
142 aTypeList.realloc (nTypeCount + 1);
143 const uno::Type aImageType =
144 cppu::UnoType<XAccessibleImage>::get();
145 aTypeList[nTypeCount] = aImageType;
147 return aTypeList;
153 /// Create the base name of this object, i.e. the name without appended number.
154 OUString
155 AccessibleGraphicShape::CreateAccessibleBaseName()
156 throw (::com::sun::star::uno::RuntimeException)
158 OUString sName;
160 ShapeTypeId nShapeType = ShapeTypeHandler::Instance().GetTypeId (mxShape);
161 switch (nShapeType)
163 case DRAWING_GRAPHIC_OBJECT:
164 sName = "GraphicObjectShape";
165 break;
167 default:
168 sName = "UnknownAccessibleGraphicShape";
169 uno::Reference<drawing::XShapeDescriptor> xDescriptor (mxShape, uno::UNO_QUERY);
170 if (xDescriptor.is())
171 sName += ": " + xDescriptor->getShapeType();
174 return sName;
177 OUString AccessibleGraphicShape::CreateAccessibleDescription()
178 throw (::com::sun::star::uno::RuntimeException)
180 //Don't use the same information for accessible name and accessible description.
181 OUString sDesc;
182 if (m_pShape)
183 sDesc = m_pShape->GetTitle();
184 if (!sDesc.isEmpty())
185 return sDesc;
186 return CreateAccessibleBaseName();
189 // Return this object's role.
190 sal_Int16 SAL_CALL AccessibleGraphicShape::getAccessibleRole()
191 throw (::com::sun::star::uno::RuntimeException, std::exception)
193 if( m_pShape->GetModel()->GetImageMapForObject(m_pShape) != NULL )
194 return AccessibleRole::IMAGE_MAP;
195 else
196 return AccessibleShape::getAccessibleRole();
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */