Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / accessibility / AccessibleFrameSelector.cxx
blob862247bd98af450d2bb8fc0122eb9438de7e4780
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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
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::lang::IndexOutOfBoundsException;
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::RuntimeException;
38 using namespace ::com::sun::star::accessibility;
41 AccFrameSelector::AccFrameSelector(FrameSelector& rFrameSel)
42 : mpFrameSel(&rFrameSel)
46 AccFrameSelector::~AccFrameSelector()
50 Reference< XAccessibleContext > AccFrameSelector::getAccessibleContext( )
52 return this;
55 sal_Int64 AccFrameSelector::getAccessibleChildCount( )
57 SolarMutexGuard aGuard;
58 IsValid();
59 return mpFrameSel->GetEnabledBorderCount();
62 Reference< XAccessible > AccFrameSelector::getAccessibleChild( sal_Int64 i )
64 SolarMutexGuard aGuard;
65 IsValid();
67 if (i < 0 || i >= getAccessibleChildCount())
68 throw IndexOutOfBoundsException();
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 sal_Int64 AccFrameSelector::getAccessibleStateSet( )
112 SolarMutexGuard aGuard;
113 sal_Int64 nStateSet = 0;
115 if(!mpFrameSel)
116 nStateSet |= AccessibleStateType::DEFUNC;
117 else
119 // add standard states
120 nStateSet |=
121 AccessibleStateType::EDITABLE |
122 AccessibleStateType::FOCUSABLE |
123 AccessibleStateType::MULTI_SELECTABLE |
124 AccessibleStateType::SELECTABLE |
125 AccessibleStateType::SHOWING |
126 AccessibleStateType::VISIBLE |
127 AccessibleStateType::OPAQUE;
128 if(mpFrameSel->IsEnabled())
130 nStateSet |= AccessibleStateType::ENABLED;
131 nStateSet |= AccessibleStateType::SENSITIVE;
134 if (mpFrameSel->HasFocus())
136 nStateSet |= AccessibleStateType::ACTIVE;
137 nStateSet |= AccessibleStateType::FOCUSED;
138 nStateSet |= AccessibleStateType::SELECTED;
141 return nStateSet;
144 Reference< XAccessible > AccFrameSelector::getAccessibleAtPoint(
145 const css::awt::Point& aPt )
147 SolarMutexGuard aGuard;
148 IsValid();
149 //aPt is relative to the frame selector
150 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
153 void AccFrameSelector::grabFocus( )
155 SolarMutexGuard aGuard;
156 IsValid();
157 mpFrameSel->GrabFocus();
160 sal_Int32 AccFrameSelector::getForeground( )
162 SolarMutexGuard aGuard;
164 //see FrameSelector::Paint
165 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
166 return sal_Int32(rStyles.GetLabelTextColor());
169 sal_Int32 AccFrameSelector::getBackground( )
171 SolarMutexGuard aGuard;
173 //see FrameSelector::Paint
174 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
175 return sal_Int32(rStyles.GetDialogColor());
178 css::awt::Rectangle AccFrameSelector::implGetBounds()
180 SolarMutexGuard aGuard;
181 IsValid();
183 css::awt::Rectangle aRet;
185 const Point aOutPos;
186 Size aOutSize(mpFrameSel->GetOutputSizePixel());
188 aRet.X = aOutPos.X();
189 aRet.Y = aOutPos.Y();
190 aRet.Width = aOutSize.Width();
191 aRet.Height = aOutSize.Height();
193 return aRet;
196 css::awt::Point AccFrameSelector::getLocationOnScreen()
198 SolarMutexGuard aGuard;
199 IsValid();
201 css::awt::Point aScreenLoc(0, 0);
203 if (weld::DrawingArea* pDrawingArea = mpFrameSel->GetDrawingArea())
205 Point aPos = pDrawingArea->get_accessible_location_on_screen();
206 aScreenLoc.X = aPos.X();
207 aScreenLoc.Y = aPos.Y();
210 return aScreenLoc;
213 void AccFrameSelector::IsValid()
215 if(!mpFrameSel)
216 throw RuntimeException();
219 void AccFrameSelector::Invalidate()
221 mpFrameSel = nullptr;
224 AccFrameSelectorChild::AccFrameSelectorChild(FrameSelector& rFrameSel, FrameBorderType eBorder)
225 : mpFrameSel(&rFrameSel)
226 , meBorder(eBorder)
230 AccFrameSelectorChild::~AccFrameSelectorChild()
234 Reference< XAccessibleContext > AccFrameSelectorChild::getAccessibleContext( )
236 return this;
239 sal_Int64 AccFrameSelectorChild::getAccessibleChildCount( )
241 SolarMutexGuard aGuard;
242 IsValid();
243 return 0;
246 Reference< XAccessible > AccFrameSelectorChild::getAccessibleChild( sal_Int64 )
248 throw RuntimeException();
251 Reference< XAccessible > AccFrameSelectorChild::getAccessibleParent( )
253 SolarMutexGuard aGuard;
254 IsValid();
255 Reference< XAccessible > xRet = mpFrameSel->CreateAccessible();
256 return xRet;
259 sal_Int16 AccFrameSelectorChild::getAccessibleRole( )
261 return AccessibleRole::CHECK_BOX;
264 OUString AccFrameSelectorChild::getAccessibleDescription( )
266 SolarMutexGuard aGuard;
267 IsValid();
268 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[static_cast<sal_uInt32>(meBorder)].first);
271 OUString AccFrameSelectorChild::getAccessibleName( )
273 SolarMutexGuard aGuard;
274 IsValid();
275 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[static_cast<sal_uInt32>(meBorder)].first);
278 Reference< XAccessibleRelationSet > AccFrameSelectorChild::getAccessibleRelationSet( )
280 SolarMutexGuard aGuard;
281 IsValid();
282 Reference< XAccessibleRelationSet > xRet = new utl::AccessibleRelationSetHelper;
283 return xRet;
286 sal_Int64 AccFrameSelectorChild::getAccessibleStateSet( )
288 SolarMutexGuard aGuard;
289 sal_Int64 nStateSet = 0;
291 if(!mpFrameSel)
292 nStateSet |= AccessibleStateType::DEFUNC;
293 else
295 nStateSet |=
296 AccessibleStateType::EDITABLE |
297 AccessibleStateType::FOCUSABLE |
298 AccessibleStateType::MULTI_SELECTABLE |
299 AccessibleStateType::SELECTABLE |
300 AccessibleStateType::SHOWING |
301 AccessibleStateType::VISIBLE |
302 AccessibleStateType::OPAQUE;
303 if(mpFrameSel->IsEnabled())
305 nStateSet |= AccessibleStateType::ENABLED;
306 nStateSet |= AccessibleStateType::SENSITIVE;
309 if (mpFrameSel->HasFocus() && mpFrameSel->IsBorderSelected(meBorder))
311 nStateSet |= AccessibleStateType::ACTIVE;
312 nStateSet |= AccessibleStateType::FOCUSED;
313 nStateSet |= AccessibleStateType::SELECTED;
316 return nStateSet;
319 Reference< XAccessible > AccFrameSelectorChild::getAccessibleAtPoint(
320 const css::awt::Point& aPt )
322 SolarMutexGuard aGuard;
323 IsValid();
324 //aPt is relative to the frame selector
325 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
328 css::awt::Rectangle AccFrameSelectorChild::implGetBounds( )
330 SolarMutexGuard aGuard;
331 IsValid();
332 const tools::Rectangle aSpot = mpFrameSel->GetClickBoundRect( meBorder );
333 Point aPos = aSpot.TopLeft();
334 Size aSz = aSpot.GetSize();
335 css::awt::Rectangle aRet;
336 aRet.X = aPos.X();
337 aRet.Y = aPos.Y();
338 aRet.Width = aSz.Width();
339 aRet.Height = aSz.Height();
340 return aRet;
343 void AccFrameSelectorChild::grabFocus( )
345 SolarMutexGuard aGuard;
346 IsValid();
347 mpFrameSel->GrabFocus();
350 sal_Int32 AccFrameSelectorChild::getForeground( )
352 SolarMutexGuard aGuard;
354 //see FrameSelector::Paint
355 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
356 return sal_Int32(rStyles.GetLabelTextColor());
359 sal_Int32 AccFrameSelectorChild::getBackground( )
361 SolarMutexGuard aGuard;
363 //see FrameSelector::Paint
364 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
365 return sal_Int32(rStyles.GetDialogColor());
368 void AccFrameSelectorChild::IsValid()
370 if(!mpFrameSel)
371 throw RuntimeException();
374 void AccFrameSelectorChild::Invalidate()
376 mpFrameSel = nullptr;
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */