1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_chartcontroller.hxx" 26 27 #include "AccessibleChartElement.hxx" 28 #include "CharacterProperties.hxx" 29 #include "ObjectIdentifier.hxx" 30 #include "ObjectNameProvider.hxx" 31 #include "servicenames.hxx" 32 #include "macros.hxx" 33 34 #include <com/sun/star/awt/XDevice.hpp> 35 #include <com/sun/star/chart2/XTitle.hpp> 36 #include <com/sun/star/beans/XMultiPropertySet.hpp> 37 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 38 #include <com/sun/star/lang/XInitialization.hpp> 39 40 // for SolarMutex 41 #include <vcl/svapp.hxx> 42 #include <rtl/ustrbuf.hxx> 43 44 // #ifndef _RTL_UUID_H_ 45 // #include <rtl/uuid.h> 46 // #endif 47 // #ifndef _CPPUHELPER_QUERYINTERFACE_HXX_ 48 // #include <cppuhelper/queryinterface.hxx> 49 // #endif 50 // #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 51 // #include <toolkit/helper/vclunohelper.hxx> 52 // #endif 53 // #ifndef _SV_WINDOW_HXX 54 // #include <vcl/window.hxx> 55 // #endif 56 57 // #ifndef _SVX_ACCESSILE_TEXT_HELPER_HXX_ 58 // #include <svx/AccessibleTextHelper.hxx> 59 // #endif 60 61 using namespace ::com::sun::star; 62 using namespace ::com::sun::star::accessibility; 63 64 using ::com::sun::star::uno::UNO_QUERY; 65 using ::rtl::OUString; 66 using ::rtl::OUStringBuffer; 67 using ::com::sun::star::uno::Reference; 68 using ::com::sun::star::uno::Sequence; 69 using ::osl::MutexGuard; 70 using ::osl::ClearableMutexGuard; 71 using ::osl::ResettableMutexGuard; 72 using ::com::sun::star::uno::RuntimeException; 73 using ::com::sun::star::uno::Any; 74 75 namespace chart 76 { 77 78 AccessibleChartElement::AccessibleChartElement( 79 const AccessibleElementInfo & rAccInfo, 80 bool bMayHaveChildren, 81 bool bAlwaysTransparent /* default: false */ ) : 82 impl::AccessibleChartElement_Base( rAccInfo, bMayHaveChildren, bAlwaysTransparent ), 83 m_bHasText( false ) 84 { 85 AddState( AccessibleStateType::TRANSIENT ); 86 } 87 88 AccessibleChartElement::~AccessibleChartElement() 89 { 90 OSL_ASSERT( CheckDisposeState( false /* don't throw exceptions */ ) ); 91 } 92 93 // ________ protected ________ 94 95 bool AccessibleChartElement::ImplUpdateChildren() 96 { 97 bool bResult = false; 98 Reference< chart2::XTitle > xTitle( 99 ObjectIdentifier::getObjectPropertySet( 100 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )), 101 uno::UNO_QUERY ); 102 m_bHasText = xTitle.is(); 103 104 if( m_bHasText ) 105 { 106 InitTextEdit(); 107 bResult = true; 108 } 109 else 110 bResult = AccessibleBase::ImplUpdateChildren(); 111 112 return bResult; 113 } 114 115 void AccessibleChartElement::InitTextEdit() 116 { 117 if( ! m_xTextHelper.is()) 118 { 119 // get hard reference 120 Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier ); 121 // get factory from selection supplier (controller) 122 Reference< lang::XMultiServiceFactory > xFact( xSelSupp, uno::UNO_QUERY ); 123 if( xFact.is()) 124 { 125 m_xTextHelper.set( 126 xFact->createInstance( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ), uno::UNO_QUERY ); 127 } 128 } 129 130 if( m_xTextHelper.is()) 131 try 132 { 133 Reference< lang::XInitialization > xInit( m_xTextHelper, uno::UNO_QUERY_THROW ); 134 Sequence< uno::Any > aArgs( 3 ); 135 aArgs[0] <<= GetInfo().m_aOID.getObjectCID(); 136 aArgs[1] <<= Reference< XAccessible >( this ); 137 aArgs[2] <<= Reference< awt::XWindow >( GetInfo().m_xWindow ); 138 xInit->initialize( aArgs ); 139 } 140 catch( const uno::Exception & ex ) 141 { 142 ASSERT_EXCEPTION( ex ); 143 } 144 } 145 // OSL_ASSERT( m_pTextHelper == 0 ); 146 147 // // /-- solar 148 // ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 149 // Window* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow )); 150 // if( pWindow ) 151 // { 152 // // we need ChartController::m_pDrawViewWrapper here 153 // SdrView * pView = 0; 154 // if( pView ) 155 // { 156 // SdrObject * pTextObj = m_pDrawViewWrapper->getTextEditObject(); 157 // if( pTextObj ) 158 // { 159 // SvxEditSource * pEditSource = new SvxEditSource( pTextObj, pView, pWindow ); 160 // m_pTextHelper = new ::accessibility::AccessibleTextHelper( 161 // ::std::auto_ptr< SvxEditSource >( pEditSource )); 162 // if( m_pTextHelper ) 163 // m_pTextHelper->SetEventSource( this ); 164 // } 165 // } 166 // } 167 // // \-- solar 168 // } 169 170 // ____________________________________ 171 // ____________________________________ 172 // 173 // Interfaces 174 // ____________________________________ 175 // ____________________________________ 176 177 // ________ AccessibleBase::XAccessibleContext ________ 178 Reference< XAccessible > AccessibleChartElement::ImplGetAccessibleChildById( sal_Int32 i ) const 179 { 180 Reference< XAccessible > xResult; 181 182 if( m_bHasText ) 183 { 184 xResult.set( m_xTextHelper->getAccessibleChild( i )); 185 // /-- solar 186 // ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 187 // if( m_pTextHelper ) 188 // xResult.set( m_pTextHelper->GetChild( i ) ); 189 // \-- solar 190 } 191 else 192 xResult.set( AccessibleBase::ImplGetAccessibleChildById( i )); 193 194 return xResult; 195 } 196 197 sal_Int32 AccessibleChartElement::ImplGetAccessibleChildCount() const 198 { 199 if( m_bHasText ) 200 { 201 if( m_xTextHelper.is()) 202 return m_xTextHelper->getAccessibleChildCount(); 203 return 0; 204 } 205 206 return AccessibleBase::ImplGetAccessibleChildCount(); 207 } 208 209 // ________ XServiceInfo ________ 210 OUString SAL_CALL AccessibleChartElement::getImplementationName() 211 { 212 return OUString( RTL_CONSTASCII_USTRINGPARAM( "AccessibleChartElement" )); 213 } 214 215 // ________ AccessibleChartElement::XAccessibleContext (overloaded) ________ 216 OUString SAL_CALL AccessibleChartElement::getAccessibleName() 217 { 218 return ObjectNameProvider::getNameForCID( 219 GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument ); 220 } 221 222 // ________ AccessibleChartElement::XAccessibleContext (overloaded) ________ 223 OUString SAL_CALL AccessibleChartElement::getAccessibleDescription() 224 { 225 return getToolTipText(); 226 } 227 228 // ________ AccessibleChartElement::XAccessibleExtendedComponent ________ 229 Reference< awt::XFont > SAL_CALL AccessibleChartElement::getFont() 230 { 231 CheckDisposeState(); 232 233 Reference< awt::XFont > xFont; 234 // using assignment for broken gcc 3.3 235 Reference< awt::XDevice > xDevice = Reference< awt::XDevice >( 236 Reference< awt::XWindow >( GetInfo().m_xWindow ), uno::UNO_QUERY ); 237 238 if( xDevice.is()) 239 { 240 Reference< beans::XMultiPropertySet > xObjProp( 241 ObjectIdentifier::getObjectPropertySet( 242 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )), uno::UNO_QUERY ); 243 awt::FontDescriptor aDescr( 244 CharacterProperties::createFontDescriptorFromPropertySet( xObjProp )); 245 xFont = xDevice->getFont( aDescr ); 246 } 247 248 return xFont; 249 } 250 251 OUString SAL_CALL AccessibleChartElement::getTitledBorderText() 252 { 253 return OUString(); 254 } 255 256 OUString SAL_CALL AccessibleChartElement::getToolTipText() 257 { 258 CheckDisposeState(); 259 260 return ObjectNameProvider::getHelpText( 261 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )); 262 } 263 264 // ________ XAccessibleComponent ________ 265 sal_Bool SAL_CALL AccessibleChartElement::containsPoint( const awt::Point& aPoint ) 266 { 267 return AccessibleBase::containsPoint( aPoint ); 268 } 269 270 Reference< XAccessible > SAL_CALL AccessibleChartElement::getAccessibleAtPoint( const awt::Point& aPoint ) 271 { 272 return AccessibleBase::getAccessibleAtPoint( aPoint ); 273 } 274 275 awt::Rectangle SAL_CALL AccessibleChartElement::getBounds() 276 { 277 return AccessibleBase::getBounds(); 278 } 279 280 awt::Point SAL_CALL AccessibleChartElement::getLocation() 281 { 282 return AccessibleBase::getLocation(); 283 } 284 285 awt::Point SAL_CALL AccessibleChartElement::getLocationOnScreen() 286 { 287 return AccessibleBase::getLocationOnScreen(); 288 } 289 290 awt::Size SAL_CALL AccessibleChartElement::getSize() 291 { 292 return AccessibleBase::getSize(); 293 } 294 295 void SAL_CALL AccessibleChartElement::grabFocus() 296 { 297 return AccessibleBase::grabFocus(); 298 } 299 300 sal_Int32 SAL_CALL AccessibleChartElement::getForeground() 301 { 302 return AccessibleBase::getForeground(); 303 } 304 305 sal_Int32 SAL_CALL AccessibleChartElement::getBackground() 306 { 307 return AccessibleBase::getBackground(); 308 } 309 310 311 } // namespace chart 312