bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / accessibility / AccessibleFrameSelector.cxx
blob3c3007fc0affeac287485c4fb78648e56ecfd594
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/accessibility/AccessibleStateType.hpp>
22 #include <com/sun/star/accessibility/AccessibleRole.hpp>
23 #include <unotools/accessiblestatesethelper.hxx>
24 #include <unotools/accessiblerelationsethelper.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
27 #include <svx/frmsel.hxx>
28 #include <svx/dialmgr.hxx>
30 #include <frmsel.hrc>
32 namespace svx::a11y {
34 using ::com::sun::star::uno::Any;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::uno::RuntimeException;
39 using namespace ::com::sun::star::accessibility;
42 AccFrameSelector::AccFrameSelector(FrameSelector& rFrameSel)
43 : mpFrameSel(&rFrameSel)
47 AccFrameSelector::~AccFrameSelector()
51 IMPLEMENT_FORWARD_XINTERFACE2( AccFrameSelector, OAccessibleComponentHelper, OAccessibleHelper_Base )
52 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccFrameSelector, OAccessibleComponentHelper, OAccessibleHelper_Base )
54 Reference< XAccessibleContext > AccFrameSelector::getAccessibleContext( )
56 return this;
59 sal_Int32 AccFrameSelector::getAccessibleChildCount( )
61 SolarMutexGuard aGuard;
62 IsValid();
63 return mpFrameSel->GetEnabledBorderCount();
66 Reference< XAccessible > AccFrameSelector::getAccessibleChild( sal_Int32 i )
68 SolarMutexGuard aGuard;
69 IsValid();
70 Reference< XAccessible > xRet = mpFrameSel->GetChildAccessible( i );
71 if( !xRet.is() )
72 throw RuntimeException();
73 return xRet;
76 Reference< XAccessible > AccFrameSelector::getAccessibleParent( )
78 SolarMutexGuard aGuard;
79 IsValid();
80 Reference< XAccessible > xRet = mpFrameSel->getAccessibleParent();
81 return xRet;
84 sal_Int16 AccFrameSelector::getAccessibleRole( )
86 return AccessibleRole::OPTION_PANE;
89 OUString AccFrameSelector::getAccessibleDescription( )
91 SolarMutexGuard aGuard;
92 IsValid();
93 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[0].first);
96 OUString AccFrameSelector::getAccessibleName( )
98 SolarMutexGuard aGuard;
99 IsValid();
100 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[0].first);
103 Reference< XAccessibleRelationSet > AccFrameSelector::getAccessibleRelationSet( )
105 SolarMutexGuard aGuard;
106 IsValid();
107 return mpFrameSel->get_accessible_relation_set();
110 Reference< XAccessibleStateSet > AccFrameSelector::getAccessibleStateSet( )
112 SolarMutexGuard aGuard;
113 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
115 if(!mpFrameSel)
116 pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
117 else
119 const sal_Int16 aStandardStates[] =
121 AccessibleStateType::EDITABLE,
122 AccessibleStateType::FOCUSABLE,
123 AccessibleStateType::MULTI_SELECTABLE,
124 AccessibleStateType::SELECTABLE,
125 AccessibleStateType::SHOWING,
126 AccessibleStateType::VISIBLE,
127 AccessibleStateType::OPAQUE,
129 sal_Int16 nState = 0;
130 while(aStandardStates[nState])
132 pStateSetHelper->AddState(aStandardStates[nState++]);
134 if(mpFrameSel->IsEnabled())
136 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
137 pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
140 if (mpFrameSel->HasFocus())
142 pStateSetHelper->AddState(AccessibleStateType::ACTIVE);
143 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
144 pStateSetHelper->AddState(AccessibleStateType::SELECTED);
147 return pStateSetHelper;
150 Reference< XAccessible > AccFrameSelector::getAccessibleAtPoint(
151 const css::awt::Point& aPt )
153 SolarMutexGuard aGuard;
154 IsValid();
155 //aPt is relative to the frame selector
156 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
159 void AccFrameSelector::grabFocus( )
161 SolarMutexGuard aGuard;
162 IsValid();
163 mpFrameSel->GrabFocus();
166 sal_Int32 AccFrameSelector::getForeground( )
168 SolarMutexGuard aGuard;
170 //see FrameSelector::Paint
171 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
172 return sal_Int32(rStyles.GetLabelTextColor());
175 sal_Int32 AccFrameSelector::getBackground( )
177 SolarMutexGuard aGuard;
179 //see FrameSelector::Paint
180 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
181 return sal_Int32(rStyles.GetDialogColor());
184 css::awt::Rectangle AccFrameSelector::implGetBounds()
186 SolarMutexGuard aGuard;
187 IsValid();
189 css::awt::Rectangle aRet;
191 const Point aOutPos;
192 Size aOutSize(mpFrameSel->GetOutputSizePixel());
194 aRet.X = aOutPos.X();
195 aRet.Y = aOutPos.Y();
196 aRet.Width = aOutSize.Width();
197 aRet.Height = aOutSize.Height();
199 return aRet;
202 void AccFrameSelector::IsValid()
204 if(!mpFrameSel)
205 throw RuntimeException();
208 void AccFrameSelector::Invalidate()
210 mpFrameSel = nullptr;
213 AccFrameSelectorChild::AccFrameSelectorChild(FrameSelector& rFrameSel, FrameBorderType eBorder)
214 : mpFrameSel(&rFrameSel)
215 , meBorder(eBorder)
219 AccFrameSelectorChild::~AccFrameSelectorChild()
223 IMPLEMENT_FORWARD_XINTERFACE2( AccFrameSelectorChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
224 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccFrameSelectorChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
226 Reference< XAccessibleContext > AccFrameSelectorChild::getAccessibleContext( )
228 return this;
231 sal_Int32 AccFrameSelectorChild::getAccessibleChildCount( )
233 SolarMutexGuard aGuard;
234 IsValid();
235 return 0;
238 Reference< XAccessible > AccFrameSelectorChild::getAccessibleChild( sal_Int32 )
240 throw RuntimeException();
243 Reference< XAccessible > AccFrameSelectorChild::getAccessibleParent( )
245 SolarMutexGuard aGuard;
246 IsValid();
247 Reference< XAccessible > xRet = mpFrameSel->CreateAccessible();
248 return xRet;
251 sal_Int16 AccFrameSelectorChild::getAccessibleRole( )
253 return AccessibleRole::CHECK_BOX;
256 OUString AccFrameSelectorChild::getAccessibleDescription( )
258 SolarMutexGuard aGuard;
259 IsValid();
260 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[static_cast<sal_uInt32>(meBorder)].first);
263 OUString AccFrameSelectorChild::getAccessibleName( )
265 SolarMutexGuard aGuard;
266 IsValid();
267 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[static_cast<sal_uInt32>(meBorder)].first);
270 Reference< XAccessibleRelationSet > AccFrameSelectorChild::getAccessibleRelationSet( )
272 SolarMutexGuard aGuard;
273 IsValid();
274 Reference< XAccessibleRelationSet > xRet = new utl::AccessibleRelationSetHelper;
275 return xRet;
278 Reference< XAccessibleStateSet > AccFrameSelectorChild::getAccessibleStateSet( )
280 SolarMutexGuard aGuard;
281 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
283 if(!mpFrameSel)
284 pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
285 else
287 const sal_Int16 aStandardStates[] =
289 AccessibleStateType::EDITABLE,
290 AccessibleStateType::FOCUSABLE,
291 AccessibleStateType::MULTI_SELECTABLE,
292 AccessibleStateType::SELECTABLE,
293 AccessibleStateType::SHOWING,
294 AccessibleStateType::VISIBLE,
295 AccessibleStateType::OPAQUE,
297 sal_Int16 nState = 0;
298 while(aStandardStates[nState])
300 pStateSetHelper->AddState(aStandardStates[nState++]);
302 if(mpFrameSel->IsEnabled())
304 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
305 pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
308 if (mpFrameSel->HasFocus() && mpFrameSel->IsBorderSelected(meBorder))
310 pStateSetHelper->AddState(AccessibleStateType::ACTIVE);
311 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
312 pStateSetHelper->AddState(AccessibleStateType::SELECTED);
315 return pStateSetHelper;
318 Reference< XAccessible > AccFrameSelectorChild::getAccessibleAtPoint(
319 const css::awt::Point& aPt )
321 SolarMutexGuard aGuard;
322 IsValid();
323 //aPt is relative to the frame selector
324 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
327 css::awt::Rectangle AccFrameSelectorChild::implGetBounds( )
329 SolarMutexGuard aGuard;
330 IsValid();
331 const tools::Rectangle aSpot = mpFrameSel->GetClickBoundRect( meBorder );
332 Point aPos = aSpot.TopLeft();
333 Size aSz = aSpot.GetSize();
334 css::awt::Rectangle aRet;
335 aRet.X = aPos.X();
336 aRet.Y = aPos.Y();
337 aRet.Width = aSz.Width();
338 aRet.Height = aSz.Height();
339 return aRet;
342 void AccFrameSelectorChild::grabFocus( )
344 SolarMutexGuard aGuard;
345 IsValid();
346 mpFrameSel->GrabFocus();
349 sal_Int32 AccFrameSelectorChild::getForeground( )
351 SolarMutexGuard aGuard;
353 //see FrameSelector::Paint
354 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
355 return sal_Int32(rStyles.GetLabelTextColor());
358 sal_Int32 AccFrameSelectorChild::getBackground( )
360 SolarMutexGuard aGuard;
362 //see FrameSelector::Paint
363 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
364 return sal_Int32(rStyles.GetDialogColor());
367 void AccFrameSelectorChild::IsValid()
369 if(!mpFrameSel)
370 throw RuntimeException();
373 void AccFrameSelectorChild::Invalidate()
375 mpFrameSel = nullptr;
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */