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
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>
29
30 #include <frmsel.hrc>
31
32 namespace svx::a11y {
33
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;
38
39 using namespace ::com::sun::star::accessibility;
40
41
AccFrameSelector(FrameSelector & rFrameSel)42 AccFrameSelector::AccFrameSelector(FrameSelector& rFrameSel)
43 : mpFrameSel(&rFrameSel)
44 {
45 }
46
~AccFrameSelector()47 AccFrameSelector::~AccFrameSelector()
48 {
49 }
50
IMPLEMENT_FORWARD_XINTERFACE2(AccFrameSelector,OAccessibleComponentHelper,OAccessibleHelper_Base)51 IMPLEMENT_FORWARD_XINTERFACE2( AccFrameSelector, OAccessibleComponentHelper, OAccessibleHelper_Base )
52 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccFrameSelector, OAccessibleComponentHelper, OAccessibleHelper_Base )
53
54 Reference< XAccessibleContext > AccFrameSelector::getAccessibleContext( )
55 {
56 return this;
57 }
58
getAccessibleChildCount()59 sal_Int32 AccFrameSelector::getAccessibleChildCount( )
60 {
61 SolarMutexGuard aGuard;
62 IsValid();
63 return mpFrameSel->GetEnabledBorderCount();
64 }
65
getAccessibleChild(sal_Int32 i)66 Reference< XAccessible > AccFrameSelector::getAccessibleChild( sal_Int32 i )
67 {
68 SolarMutexGuard aGuard;
69 IsValid();
70 Reference< XAccessible > xRet = mpFrameSel->GetChildAccessible( i );
71 if( !xRet.is() )
72 throw RuntimeException();
73 return xRet;
74 }
75
getAccessibleParent()76 Reference< XAccessible > AccFrameSelector::getAccessibleParent( )
77 {
78 SolarMutexGuard aGuard;
79 IsValid();
80 Reference< XAccessible > xRet = mpFrameSel->getAccessibleParent();
81 return xRet;
82 }
83
getAccessibleRole()84 sal_Int16 AccFrameSelector::getAccessibleRole( )
85 {
86 return AccessibleRole::OPTION_PANE;
87 }
88
getAccessibleDescription()89 OUString AccFrameSelector::getAccessibleDescription( )
90 {
91 SolarMutexGuard aGuard;
92 IsValid();
93 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[0].first);
94 }
95
getAccessibleName()96 OUString AccFrameSelector::getAccessibleName( )
97 {
98 SolarMutexGuard aGuard;
99 IsValid();
100 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[0].first);
101 }
102
getAccessibleRelationSet()103 Reference< XAccessibleRelationSet > AccFrameSelector::getAccessibleRelationSet( )
104 {
105 SolarMutexGuard aGuard;
106 IsValid();
107 return mpFrameSel->get_accessible_relation_set();
108 }
109
getAccessibleStateSet()110 Reference< XAccessibleStateSet > AccFrameSelector::getAccessibleStateSet( )
111 {
112 SolarMutexGuard aGuard;
113 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
114
115 if(!mpFrameSel)
116 pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
117 else
118 {
119 const sal_Int16 aStandardStates[] =
120 {
121 AccessibleStateType::EDITABLE,
122 AccessibleStateType::FOCUSABLE,
123 AccessibleStateType::MULTI_SELECTABLE,
124 AccessibleStateType::SELECTABLE,
125 AccessibleStateType::SHOWING,
126 AccessibleStateType::VISIBLE,
127 AccessibleStateType::OPAQUE,
128 0};
129 sal_Int16 nState = 0;
130 while(aStandardStates[nState])
131 {
132 pStateSetHelper->AddState(aStandardStates[nState++]);
133 }
134 if(mpFrameSel->IsEnabled())
135 {
136 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
137 pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
138 }
139
140 if (mpFrameSel->HasFocus())
141 {
142 pStateSetHelper->AddState(AccessibleStateType::ACTIVE);
143 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
144 pStateSetHelper->AddState(AccessibleStateType::SELECTED);
145 }
146 }
147 return pStateSetHelper;
148 }
149
getAccessibleAtPoint(const css::awt::Point & aPt)150 Reference< XAccessible > AccFrameSelector::getAccessibleAtPoint(
151 const css::awt::Point& aPt )
152 {
153 SolarMutexGuard aGuard;
154 IsValid();
155 //aPt is relative to the frame selector
156 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
157 }
158
grabFocus()159 void AccFrameSelector::grabFocus( )
160 {
161 SolarMutexGuard aGuard;
162 IsValid();
163 mpFrameSel->GrabFocus();
164 }
165
getForeground()166 sal_Int32 AccFrameSelector::getForeground( )
167 {
168 SolarMutexGuard aGuard;
169
170 //see FrameSelector::Paint
171 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
172 return sal_Int32(rStyles.GetLabelTextColor());
173 }
174
getBackground()175 sal_Int32 AccFrameSelector::getBackground( )
176 {
177 SolarMutexGuard aGuard;
178
179 //see FrameSelector::Paint
180 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
181 return sal_Int32(rStyles.GetDialogColor());
182 }
183
implGetBounds()184 css::awt::Rectangle AccFrameSelector::implGetBounds()
185 {
186 SolarMutexGuard aGuard;
187 IsValid();
188
189 css::awt::Rectangle aRet;
190
191 const Point aOutPos;
192 Size aOutSize(mpFrameSel->GetOutputSizePixel());
193
194 aRet.X = aOutPos.X();
195 aRet.Y = aOutPos.Y();
196 aRet.Width = aOutSize.Width();
197 aRet.Height = aOutSize.Height();
198
199 return aRet;
200 }
201
IsValid()202 void AccFrameSelector::IsValid()
203 {
204 if(!mpFrameSel)
205 throw RuntimeException();
206 }
207
Invalidate()208 void AccFrameSelector::Invalidate()
209 {
210 mpFrameSel = nullptr;
211 }
212
AccFrameSelectorChild(FrameSelector & rFrameSel,FrameBorderType eBorder)213 AccFrameSelectorChild::AccFrameSelectorChild(FrameSelector& rFrameSel, FrameBorderType eBorder)
214 : mpFrameSel(&rFrameSel)
215 , meBorder(eBorder)
216 {
217 }
218
~AccFrameSelectorChild()219 AccFrameSelectorChild::~AccFrameSelectorChild()
220 {
221 }
222
IMPLEMENT_FORWARD_XINTERFACE2(AccFrameSelectorChild,OAccessibleComponentHelper,OAccessibleHelper_Base)223 IMPLEMENT_FORWARD_XINTERFACE2( AccFrameSelectorChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
224 IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccFrameSelectorChild, OAccessibleComponentHelper, OAccessibleHelper_Base )
225
226 Reference< XAccessibleContext > AccFrameSelectorChild::getAccessibleContext( )
227 {
228 return this;
229 }
230
getAccessibleChildCount()231 sal_Int32 AccFrameSelectorChild::getAccessibleChildCount( )
232 {
233 SolarMutexGuard aGuard;
234 IsValid();
235 return 0;
236 }
237
getAccessibleChild(sal_Int32)238 Reference< XAccessible > AccFrameSelectorChild::getAccessibleChild( sal_Int32 )
239 {
240 throw RuntimeException();
241 }
242
getAccessibleParent()243 Reference< XAccessible > AccFrameSelectorChild::getAccessibleParent( )
244 {
245 SolarMutexGuard aGuard;
246 IsValid();
247 Reference< XAccessible > xRet = mpFrameSel->CreateAccessible();
248 return xRet;
249 }
250
getAccessibleRole()251 sal_Int16 AccFrameSelectorChild::getAccessibleRole( )
252 {
253 return AccessibleRole::CHECK_BOX;
254 }
255
getAccessibleDescription()256 OUString AccFrameSelectorChild::getAccessibleDescription( )
257 {
258 SolarMutexGuard aGuard;
259 IsValid();
260 return SvxResId(RID_SVXSTR_FRMSEL_DESCRIPTIONS[static_cast<sal_uInt32>(meBorder)].first);
261 }
262
getAccessibleName()263 OUString AccFrameSelectorChild::getAccessibleName( )
264 {
265 SolarMutexGuard aGuard;
266 IsValid();
267 return SvxResId(RID_SVXSTR_FRMSEL_TEXTS[static_cast<sal_uInt32>(meBorder)].first);
268 }
269
getAccessibleRelationSet()270 Reference< XAccessibleRelationSet > AccFrameSelectorChild::getAccessibleRelationSet( )
271 {
272 SolarMutexGuard aGuard;
273 IsValid();
274 Reference< XAccessibleRelationSet > xRet = new utl::AccessibleRelationSetHelper;
275 return xRet;
276 }
277
getAccessibleStateSet()278 Reference< XAccessibleStateSet > AccFrameSelectorChild::getAccessibleStateSet( )
279 {
280 SolarMutexGuard aGuard;
281 rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper = new utl::AccessibleStateSetHelper;
282
283 if(!mpFrameSel)
284 pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
285 else
286 {
287 const sal_Int16 aStandardStates[] =
288 {
289 AccessibleStateType::EDITABLE,
290 AccessibleStateType::FOCUSABLE,
291 AccessibleStateType::MULTI_SELECTABLE,
292 AccessibleStateType::SELECTABLE,
293 AccessibleStateType::SHOWING,
294 AccessibleStateType::VISIBLE,
295 AccessibleStateType::OPAQUE,
296 0};
297 sal_Int16 nState = 0;
298 while(aStandardStates[nState])
299 {
300 pStateSetHelper->AddState(aStandardStates[nState++]);
301 }
302 if(mpFrameSel->IsEnabled())
303 {
304 pStateSetHelper->AddState(AccessibleStateType::ENABLED);
305 pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
306 }
307
308 if (mpFrameSel->HasFocus() && mpFrameSel->IsBorderSelected(meBorder))
309 {
310 pStateSetHelper->AddState(AccessibleStateType::ACTIVE);
311 pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
312 pStateSetHelper->AddState(AccessibleStateType::SELECTED);
313 }
314 }
315 return pStateSetHelper;
316 }
317
getAccessibleAtPoint(const css::awt::Point & aPt)318 Reference< XAccessible > AccFrameSelectorChild::getAccessibleAtPoint(
319 const css::awt::Point& aPt )
320 {
321 SolarMutexGuard aGuard;
322 IsValid();
323 //aPt is relative to the frame selector
324 return mpFrameSel->GetChildAccessible( Point( aPt.X, aPt.Y ) );
325 }
326
implGetBounds()327 css::awt::Rectangle AccFrameSelectorChild::implGetBounds( )
328 {
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;
340 }
341
grabFocus()342 void AccFrameSelectorChild::grabFocus( )
343 {
344 SolarMutexGuard aGuard;
345 IsValid();
346 mpFrameSel->GrabFocus();
347 }
348
getForeground()349 sal_Int32 AccFrameSelectorChild::getForeground( )
350 {
351 SolarMutexGuard aGuard;
352
353 //see FrameSelector::Paint
354 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
355 return sal_Int32(rStyles.GetLabelTextColor());
356 }
357
getBackground()358 sal_Int32 AccFrameSelectorChild::getBackground( )
359 {
360 SolarMutexGuard aGuard;
361
362 //see FrameSelector::Paint
363 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings();
364 return sal_Int32(rStyles.GetDialogColor());
365 }
366
IsValid()367 void AccFrameSelectorChild::IsValid()
368 {
369 if(!mpFrameSel)
370 throw RuntimeException();
371 }
372
Invalidate()373 void AccFrameSelectorChild::Invalidate()
374 {
375 mpFrameSel = nullptr;
376 }
377
378 }
379
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
381