LibreOffice Module basctl (master) 1
accessibledialogcontrolshape.cxx
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
21#include <baside3.hxx>
22#include <dlgeddef.hxx>
23#include <dlgedview.hxx>
24#include <dlgedobj.hxx>
25#include <com/sun/star/awt/XVclWindowPeer.hpp>
26#include <com/sun/star/accessibility/AccessibleEventId.hpp>
27#include <com/sun/star/accessibility/AccessibleRole.hpp>
28#include <com/sun/star/accessibility/AccessibleStateType.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
37#include <vcl/svapp.hxx>
38#include <vcl/settings.hxx>
40
41namespace basctl
42{
43
44using namespace ::com::sun::star;
45using namespace ::com::sun::star::uno;
46using namespace ::com::sun::star::lang;
47using namespace ::com::sun::star::beans;
48using namespace ::com::sun::star::accessibility;
49using namespace ::comphelper;
50
51
52
53
55 :m_pDialogWindow( pDialogWindow )
56 ,m_pDlgEdObj( pDlgEdObj )
57{
58 if ( m_pDlgEdObj )
60
61 if ( m_xControlModel.is() )
62 m_xControlModel->addPropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
63
67}
68
69
71{
72 if ( m_xControlModel.is() )
73 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
74}
75
76
78{
79 bool bFocused = false;
80 if ( m_pDialogWindow )
81 {
82 SdrView& rView = m_pDialogWindow->GetView();
83 if (rView.IsObjMarked(m_pDlgEdObj) && rView.GetMarkedObjectList().GetMarkCount() == 1)
84 bFocused = true;
85 }
86
87 return bFocused;
88}
89
90
92{
93 if ( m_pDialogWindow )
94 return m_pDialogWindow->GetView().IsObjMarked(m_pDlgEdObj);
95 return false;
96}
97
98
100{
101 if ( m_bFocused != bFocused )
102 {
103 Any aOldValue, aNewValue;
104 if ( m_bFocused )
105 aOldValue <<= AccessibleStateType::FOCUSED;
106 else
107 aNewValue <<= AccessibleStateType::FOCUSED;
108 m_bFocused = bFocused;
109 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
110 }
111}
112
113
115{
116 if ( m_bSelected != bSelected )
117 {
118 Any aOldValue, aNewValue;
119 if ( m_bSelected )
120 aOldValue <<= AccessibleStateType::SELECTED;
121 else
122 aNewValue <<= AccessibleStateType::SELECTED;
123 m_bSelected = bSelected;
124 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
125 }
126}
127
128
130{
131 awt::Rectangle aBounds( 0, 0, 0, 0 );
132 if ( m_pDlgEdObj )
133 {
134 // get the bounding box of the shape in logic units
136
137 if ( m_pDialogWindow )
138 {
139 // transform coordinates relative to the parent
140 MapMode aMap = m_pDialogWindow->GetMapMode();
141 Point aOrg = aMap.GetOrigin();
142 aRect.Move( aOrg.X(), aOrg.Y() );
143
144 // convert logic units to pixel
145 aRect = m_pDialogWindow->LogicToPixel( aRect, MapMode(MapUnit::Map100thMM) );
146
147 // clip the shape's bounding box with the bounding box of its parent
148 tools::Rectangle aParentRect( Point( 0, 0 ), m_pDialogWindow->GetSizePixel() );
149 aRect = aRect.GetIntersection( aParentRect );
150 aBounds = AWTRectangle( aRect );
151 }
152 }
153
154 return aBounds;
155}
156
157
158void AccessibleDialogControlShape::SetBounds( const awt::Rectangle& aBounds )
159{
160 if ( m_aBounds.X != aBounds.X || m_aBounds.Y != aBounds.Y || m_aBounds.Width != aBounds.Width || m_aBounds.Height != aBounds.Height )
161 {
162 m_aBounds = aBounds;
163 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
164 }
165}
166
167
169{
170 vcl::Window* pWindow = nullptr;
171 if ( m_pDlgEdObj )
172 {
174 if ( xControl.is() )
175 pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() );
176 }
177
178 return pWindow;
179}
180
181
182OUString AccessibleDialogControlShape::GetModelStringProperty( OUString const & pPropertyName )
183{
184 OUString sReturn;
185
186 try
187 {
188 if ( m_xControlModel.is() )
189 {
190 Reference< XPropertySetInfo > xInfo = m_xControlModel->getPropertySetInfo();
191 if ( xInfo.is() && xInfo->hasPropertyByName( pPropertyName ) )
192 m_xControlModel->getPropertyValue( pPropertyName ) >>= sReturn;
193 }
194 }
195 catch ( const Exception& )
196 {
197 TOOLS_WARN_EXCEPTION( "basctl", "AccessibleDialogControlShape::GetModelStringProperty" );
198 }
199
200 return sReturn;
201}
202
203
205{
206 rStateSet |= AccessibleStateType::ENABLED;
207
208 rStateSet |= AccessibleStateType::VISIBLE;
209
210 rStateSet |= AccessibleStateType::SHOWING;
211
212 rStateSet |= AccessibleStateType::FOCUSABLE;
213
214 if ( IsFocused() )
215 rStateSet |= AccessibleStateType::FOCUSED;
216
217 rStateSet |= AccessibleStateType::SELECTABLE;
218
219 if ( IsSelected() )
220 rStateSet |= AccessibleStateType::SELECTED;
221
222 rStateSet |= AccessibleStateType::RESIZABLE;
223}
224
225// OCommonAccessibleComponent
227{
228 return GetBounds();
229}
230
231// XComponent
233{
234 OAccessibleExtendedComponentHelper::disposing();
235
236 m_pDialogWindow = nullptr;
237 m_pDlgEdObj = nullptr;
238
239 if ( m_xControlModel.is() )
240 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
241 m_xControlModel.clear();
242}
243
244
245// XEventListener
246
247
248void AccessibleDialogControlShape::disposing( const lang::EventObject& )
249{
250 if ( m_xControlModel.is() )
251 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
252 m_xControlModel.clear();
253}
254
255
256// XPropertyChangeListener
257
258
259void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent& rEvent )
260{
261 if ( rEvent.PropertyName == DLGED_PROP_NAME )
262 {
263 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, rEvent.OldValue, rEvent.NewValue );
264 }
265 else if ( rEvent.PropertyName == DLGED_PROP_POSITIONX ||
266 rEvent.PropertyName == DLGED_PROP_POSITIONY ||
267 rEvent.PropertyName == DLGED_PROP_WIDTH ||
268 rEvent.PropertyName == DLGED_PROP_HEIGHT )
269 {
270 SetBounds( GetBounds() );
271 }
272 else if ( rEvent.PropertyName == DLGED_PROP_BACKGROUNDCOLOR ||
273 rEvent.PropertyName == DLGED_PROP_TEXTCOLOR ||
274 rEvent.PropertyName == DLGED_PROP_TEXTLINECOLOR )
275 {
276 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any() );
277 }
278}
279
280// XServiceInfo
282{
283 return "com.sun.star.comp.basctl.AccessibleShape";
284}
285
287{
288 return cppu::supportsService(this, rServiceName);
289}
290
292{
293 return { "com.sun.star.drawing.AccessibleShape" };
294}
295
296// XAccessible
298{
299 return this;
300}
301
302// XAccessibleContext
304{
305 return 0;
306}
307
308
310{
311 OExternalLockGuard aGuard( this );
312
313 if ( i < 0 || i >= getAccessibleChildCount() )
314 throw IndexOutOfBoundsException();
315
317}
318
319
321{
322 OExternalLockGuard aGuard( this );
323
325 if ( m_pDialogWindow )
326 xParent = m_pDialogWindow->GetAccessible();
327
328 return xParent;
329}
330
331
333{
334 OExternalLockGuard aGuard( this );
335
336 sal_Int64 nIndexInParent = -1;
338 if ( xParent.is() )
339 {
340 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
341 if ( xParentContext.is() )
342 {
343 for ( sal_Int64 i = 0, nCount = xParentContext->getAccessibleChildCount(); i < nCount; ++i )
344 {
345 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
346 if ( xChild.is() )
347 {
348 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
349 if ( xChildContext == static_cast<XAccessibleContext*>(this) )
350 {
351 nIndexInParent = i;
352 break;
353 }
354 }
355 }
356 }
357 }
358
359 return nIndexInParent;
360}
361
362
364{
365 OExternalLockGuard aGuard( this );
366
367 return AccessibleRole::SHAPE;
368}
369
370
372{
373 OExternalLockGuard aGuard( this );
374
375 return GetModelStringProperty( "HelpText" );
376}
377
378
380{
381 OExternalLockGuard aGuard( this );
382
383 return GetModelStringProperty( "Name" );
384}
385
386
388{
389 OExternalLockGuard aGuard( this );
390
392}
393
394
396{
397 OExternalLockGuard aGuard( this );
398
399 sal_Int64 nStateSet = 0;
400
401 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
402 {
403 FillAccessibleStateSet( nStateSet );
404 }
405 else
406 {
407 nStateSet |= AccessibleStateType::DEFUNC;
408 }
409
410 return nStateSet;
411}
412
413
415{
416 OExternalLockGuard aGuard( this );
417
419}
420
421
422// XAccessibleComponent
423
424
426{
427 OExternalLockGuard aGuard( this );
428
430}
431
432
434{
435 // no focus for shapes
436}
437
438
440{
441 OExternalLockGuard aGuard( this );
442
443 Color nColor;
444 vcl::Window* pWindow = GetWindow();
445 if ( pWindow )
446 {
447 if ( pWindow->IsControlForeground() )
448 nColor = pWindow->GetControlForeground();
449 else
450 {
451 vcl::Font aFont;
452 if ( pWindow->IsControlFont() )
453 aFont = pWindow->GetControlFont();
454 else
455 aFont = pWindow->GetFont();
456 nColor = aFont.GetColor();
457 }
458 }
459
460 return sal_Int32(nColor);
461}
462
463
465{
466 OExternalLockGuard aGuard( this );
467
468 Color nColor;
469 vcl::Window* pWindow = GetWindow();
470 if ( pWindow )
471 {
472 if ( pWindow->IsControlBackground() )
473 nColor = pWindow->GetControlBackground();
474 else
475 nColor = pWindow->GetBackground().GetColor();
476 }
477
478 return sal_Int32(nColor);
479}
480
481
482// XAccessibleExtendedComponent
483
484
486{
487 OExternalLockGuard aGuard( this );
488
490 vcl::Window* pWindow = GetWindow();
491 if ( pWindow )
492 {
493 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
494 if ( xDev.is() )
495 {
496 vcl::Font aFont;
497 if ( pWindow->IsControlFont() )
498 aFont = pWindow->GetControlFont();
499 else
500 aFont = pWindow->GetFont();
501 rtl::Reference<VCLXFont> pVCLXFont = new VCLXFont;
502 pVCLXFont->Init( *xDev, aFont );
503 xFont = pVCLXFont;
504 }
505 }
506
507 return xFont;
508}
509
510
512{
513 OExternalLockGuard aGuard( this );
514
515 return OUString();
516}
517
518
520{
521 OExternalLockGuard aGuard( this );
522
523 OUString sText;
524 vcl::Window* pWindow = GetWindow();
525 if ( pWindow )
526 sText = pWindow->GetQuickHelpText();
527
528 return sText;
529}
530
531
532} // namespace basctl
533
534/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pPropertyName
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
constexpr tools::Long Y() const
constexpr tools::Long X() const
virtual const tools::Rectangle & GetSnapRect() const override
size_t GetMarkCount() const
bool IsObjMarked(SdrObject const *pObj) const
const SdrMarkList & GetMarkedObjectList() const
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
const Color & GetColor() const
virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
virtual OUString SAL_CALL getToolTipText() override
OUString GetModelStringProperty(OUString const &pPropertyName)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual OUString SAL_CALL getAccessibleName() override
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &rEvent) override
virtual sal_Int32 SAL_CALL getForeground() override
virtual OUString SAL_CALL getAccessibleDescription() override
void SetBounds(const css::awt::Rectangle &aBounds)
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
AccessibleDialogControlShape(DialogWindow *, DlgEdObj *)
virtual sal_Int64 SAL_CALL getAccessibleStateSet() override
virtual OUString SAL_CALL getTitledBorderText() override
virtual sal_Int32 SAL_CALL getBackground() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint(const css::awt::Point &aPoint) override
virtual css::awt::Rectangle implGetBounds() override
virtual sal_Int64 SAL_CALL getAccessibleIndexInParent() override
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual css::uno::Reference< css::awt::XFont > SAL_CALL getFont() override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
css::uno::Reference< css::beans::XPropertySet > m_xControlModel
css::uno::Reference< css::awt::XControl > GetControl() const
Definition: dlgedobj.cxx:148
tools::Rectangle GetIntersection(const tools::Rectangle &rRect) const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
const Color & GetColor() const
const Wallpaper & GetBackground() const
bool IsControlFont() const
const Color & GetControlForeground() const
bool IsControlForeground() const
vcl::Font GetControlFont() const
const vcl::Font & GetFont() const
virtual css::uno::Reference< css::awt::XVclWindowPeer > GetComponentInterface(bool bCreate=true)
bool IsControlBackground() const
const Color & GetControlBackground() const
const OUString & GetQuickHelpText() const
css::awt::Rectangle AWTRectangle(const ::tools::Rectangle &rVCLRect)
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DLGED_PROP_TEXTLINECOLOR
Definition: dlgeddef.hxx:40
#define DLGED_PROP_TEXTCOLOR
Definition: dlgeddef.hxx:39
#define DLGED_PROP_BACKGROUNDCOLOR
Definition: dlgeddef.hxx:28
constexpr OUStringLiteral DLGED_PROP_NAME
Definition: dlgeddef.hxx:33
constexpr OUStringLiteral DLGED_PROP_WIDTH
Definition: dlgeddef.hxx:41
constexpr OUStringLiteral DLGED_PROP_POSITIONX
Definition: dlgeddef.hxx:35
constexpr OUStringLiteral DLGED_PROP_HEIGHT
Definition: dlgeddef.hxx:31
constexpr OUStringLiteral DLGED_PROP_POSITIONY
Definition: dlgeddef.hxx:36
@ Exception
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
HashMap_OWString_Interface aMap
unsigned char sal_Bool