Bump version to 6.4.7.2.M8
[LibreOffice.git] / svx / source / accessibility / AccessibleFrameSelector.cxx
blobe180bec3538b4b54390afda093650192c0a56e75
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 <AccessibleFrameSelector.hxx>
21 #include <com/sun/star/awt/KeyEvent.hpp>
22 #include <com/sun/star/awt/KeyModifier.hpp>
23 #include <com/sun/star/awt/Key.hpp>
24 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
25 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
26 #include <com/sun/star/accessibility/AccessibleRole.hpp>
27 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
28 #include <com/sun/star/awt/FocusChangeReason.hpp>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/accessiblestatesethelper.hxx>
31 #include <unotools/accessiblerelationsethelper.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/settings.hxx>
34 #include <svx/frmsel.hxx>
35 #include <svx/dialmgr.hxx>
36 #include <editeng/unolingu.hxx>
38 #include <svx/strings.hrc>
39 #include <frmsel.hrc>
41 namespace svx {
42 namespace a11y {
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::UNO_QUERY;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Sequence;
48 using ::com::sun::star::uno::RuntimeException;
49 using ::com::sun::star::uno::XInterface;
50 using ::com::sun::star::lang::Locale;
51 using ::com::sun::star::lang::EventObject;
52 using ::com::sun::star::awt::XFocusListener;
54 using namespace ::com::sun::star::accessibility;
57 AccFrameSelector::AccFrameSelector(FrameSelector& rFrameSel)
58 : mpFrameSel(&rFrameSel)
62 AccFrameSelector::~AccFrameSelector()
66 IMPLEMENT_FORWARD_XINTERFACE2( AccFrameSelector, OAccessibleComponentHelper, OAccessibleHelper_Base )
67 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccFrameSelector, OAccessibleComponentHelper, OAccessibleHelper_Base )
69 Reference< XAccessibleContext > AccFrameSelector::getAccessibleContext( )
71 return this;
74 sal_Int32 AccFrameSelector::getAccessibleChildCount( )
76 SolarMutexGuard aGuard;
77 IsValid();
78 return mpFrameSel->GetEnabledBorderCount();
81 Reference< XAccessible > AccFrameSelector::getAccessibleChild( sal_Int32 i )
83 SolarMutexGuard aGuard;
84 IsValid();
85 Reference< XAccessible > xRet = mpFrameSel->GetChildAccessible( i );
86 if( !xRet.is() )
87 throw RuntimeException();
88 return xRet;
91 Reference< XAccessible > AccFrameSelector::getAccessibleParent( )
93 SolarMutexGuard aGuard;
94 IsValid();
95 Reference< XAccessible > xRet = mpFrameSel->getAccessibleParent();
96 return xRet;
99 sal_Int16 AccFrameSelector::getAccessibleRole( )
101 return AccessibleRole::OPTION_PANE;
104 OUString AccFrameSelector::getAccessibleDescription( )
106 SolarMutexGuard aGuard;
107 IsValid();
108 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[0].first);
111 OUString AccFrameSelector::getAccessibleName( )
113 SolarMutexGuard aGuard;
114 IsValid();
115 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[0].first);
118 Reference< XAccessibleRelationSet > AccFrameSelector::getAccessibleRelationSet( )
120 SolarMutexGuard aGuard;
121 IsValid();
122 return mpFrameSel->get_accessible_relation_set();
125 Reference< XAccessibleStateSet > AccFrameSelector::getAccessibleStateSet( )
127 SolarMutexGuard aGuard;
128 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
129 Reference< XAccessibleStateSet > xRet = pStateSetHelper;
131 if(!mpFrameSel)
132 pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
133 else
135 const sal_Int16 aStandardStates[] =
137 AccessibleStateType::EDITABLE,
138 AccessibleStateType::FOCUSABLE,
139 AccessibleStateType::MULTI_SELECTABLE,
140 AccessibleStateType::SELECTABLE,
141 AccessibleStateType::SHOWING,
142 AccessibleStateType::VISIBLE,
143 AccessibleStateType::OPAQUE,
145 sal_Int16 nState = 0;
146 while(aStandardStates[nState])
148 pStateSetHelper->AddState(aStandardStates[nState++]);
150 if(mpFrameSel->IsEnabled())
152 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
153 pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
156 if (mpFrameSel->HasFocus())
158 pStateSetHelper->AddState(AccessibleStateType::ACTIVE);
159 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
160 pStateSetHelper->AddState(AccessibleStateType::SELECTED);
163 return xRet;
166 Reference< XAccessible > AccFrameSelector::getAccessibleAtPoint(
167 const css::awt::Point& aPt )
169 SolarMutexGuard aGuard;
170 IsValid();
171 //aPt is relative to the frame selector
172 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
175 void AccFrameSelector::grabFocus( )
177 SolarMutexGuard aGuard;
178 IsValid();
179 mpFrameSel->GrabFocus();
182 sal_Int32 AccFrameSelector::getForeground( )
184 SolarMutexGuard aGuard;
186 //see FrameSelector::Paint
187 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
188 return sal_Int32(rStyles.GetLabelTextColor());
191 sal_Int32 AccFrameSelector::getBackground( )
193 SolarMutexGuard aGuard;
195 //see FrameSelector::Paint
196 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
197 return sal_Int32(rStyles.GetDialogColor());
200 css::awt::Rectangle AccFrameSelector::implGetBounds()
202 SolarMutexGuard aGuard;
203 IsValid();
205 css::awt::Rectangle aRet;
207 const Point aOutPos;
208 Size aOutSize(mpFrameSel->GetOutputSizePixel());
210 aRet.X = aOutPos.X();
211 aRet.Y = aOutPos.Y();
212 aRet.Width = aOutSize.Width();
213 aRet.Height = aOutSize.Height();
215 return aRet;
218 void AccFrameSelector::IsValid()
220 if(!mpFrameSel)
221 throw RuntimeException();
224 void AccFrameSelector::Invalidate()
226 mpFrameSel = nullptr;
229 AccFrameSelectorChild::AccFrameSelectorChild(FrameSelector& rFrameSel, FrameBorderType eBorder)
230 : mpFrameSel(&rFrameSel)
231 , meBorder(eBorder)
235 AccFrameSelectorChild::~AccFrameSelectorChild()
239 IMPLEMENT_FORWARD_XINTERFACE2( AccFrameSelectorChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
240 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccFrameSelectorChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
242 Reference< XAccessibleContext > AccFrameSelectorChild::getAccessibleContext( )
244 return this;
247 sal_Int32 AccFrameSelectorChild::getAccessibleChildCount( )
249 SolarMutexGuard aGuard;
250 IsValid();
251 return 0;
254 Reference< XAccessible > AccFrameSelectorChild::getAccessibleChild( sal_Int32 )
256 throw RuntimeException();
259 Reference< XAccessible > AccFrameSelectorChild::getAccessibleParent( )
261 SolarMutexGuard aGuard;
262 IsValid();
263 Reference< XAccessible > xRet = mpFrameSel->CreateAccessible();
264 return xRet;
267 sal_Int16 AccFrameSelectorChild::getAccessibleRole( )
269 return AccessibleRole::CHECK_BOX;
272 OUString AccFrameSelectorChild::getAccessibleDescription( )
274 SolarMutexGuard aGuard;
275 IsValid();
276 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[static_cast<sal_uInt32>(meBorder)].first);
279 OUString AccFrameSelectorChild::getAccessibleName( )
281 SolarMutexGuard aGuard;
282 IsValid();
283 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[static_cast<sal_uInt32>(meBorder)].first);
286 Reference< XAccessibleRelationSet > AccFrameSelectorChild::getAccessibleRelationSet( )
288 SolarMutexGuard aGuard;
289 IsValid();
290 utl::AccessibleRelationSetHelper* pHelper;
291 Reference< XAccessibleRelationSet > xRet = pHelper = new utl::AccessibleRelationSetHelper;
292 return xRet;
295 Reference< XAccessibleStateSet > AccFrameSelectorChild::getAccessibleStateSet( )
297 SolarMutexGuard aGuard;
298 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
299 Reference< XAccessibleStateSet > xRet = pStateSetHelper;
301 if(!mpFrameSel)
302 pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
303 else
305 const sal_Int16 aStandardStates[] =
307 AccessibleStateType::EDITABLE,
308 AccessibleStateType::FOCUSABLE,
309 AccessibleStateType::MULTI_SELECTABLE,
310 AccessibleStateType::SELECTABLE,
311 AccessibleStateType::SHOWING,
312 AccessibleStateType::VISIBLE,
313 AccessibleStateType::OPAQUE,
315 sal_Int16 nState = 0;
316 while(aStandardStates[nState])
318 pStateSetHelper->AddState(aStandardStates[nState++]);
320 if(mpFrameSel->IsEnabled())
322 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
323 pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
326 if (mpFrameSel->HasFocus() && mpFrameSel->IsBorderSelected(meBorder))
328 pStateSetHelper->AddState(AccessibleStateType::ACTIVE);
329 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
330 pStateSetHelper->AddState(AccessibleStateType::SELECTED);
333 return xRet;
336 Reference< XAccessible > AccFrameSelectorChild::getAccessibleAtPoint(
337 const css::awt::Point& aPt )
339 SolarMutexGuard aGuard;
340 IsValid();
341 //aPt is relative to the frame selector
342 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
345 css::awt::Rectangle AccFrameSelectorChild::implGetBounds( )
347 SolarMutexGuard aGuard;
348 IsValid();
349 const tools::Rectangle aSpot = mpFrameSel->GetClickBoundRect( meBorder );
350 Point aPos = aSpot.TopLeft();
351 Size aSz = aSpot.GetSize();
352 css::awt::Rectangle aRet;
353 aRet.X = aPos.X();
354 aRet.Y = aPos.Y();
355 aRet.Width = aSz.Width();
356 aRet.Height = aSz.Height();
357 return aRet;
360 void AccFrameSelectorChild::grabFocus( )
362 SolarMutexGuard aGuard;
363 IsValid();
364 mpFrameSel->GrabFocus();
367 sal_Int32 AccFrameSelectorChild::getForeground( )
369 SolarMutexGuard aGuard;
371 //see FrameSelector::Paint
372 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
373 return sal_Int32(rStyles.GetLabelTextColor());
376 sal_Int32 AccFrameSelectorChild::getBackground( )
378 SolarMutexGuard aGuard;
380 //see FrameSelector::Paint
381 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
382 return sal_Int32(rStyles.GetDialogColor());
385 void AccFrameSelectorChild::IsValid()
387 if(!mpFrameSel)
388 throw RuntimeException();
391 void AccFrameSelectorChild::Invalidate()
393 mpFrameSel = nullptr;
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */