1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 
26 #include "precompiled_sc.hxx"
27 #include "AccessibleGlobal.hxx"
28 #include "AccessibleFilterMenuItem.hxx"
29 #include "dpcontrol.hxx"
30 
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
36 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37 #include <com/sun/star/accessibility/TextSegment.hpp>
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
41 using namespace ::com::sun::star::accessibility::AccessibleStateType;
42 
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::Reference;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::UNO_QUERY;
47 using ::com::sun::star::lang::IndexOutOfBoundsException;
48 using ::com::sun::star::uno::RuntimeException;
49 using ::rtl::OUString;
50 
ScAccessibleFilterMenuItem(const Reference<XAccessible> & rxParent,ScMenuFloatingWindow * pWin,const OUString & rName,size_t nMenuPos)51 ScAccessibleFilterMenuItem::ScAccessibleFilterMenuItem(
52     const Reference<XAccessible>& rxParent, ScMenuFloatingWindow* pWin, const OUString& rName, size_t nMenuPos) :
53     ScAccessibleContextBase(rxParent, AccessibleRole::MENU_ITEM),
54     mpWindow(pWin),
55     maName(rName),
56     mnMenuPos(nMenuPos),
57     mbEnabled(true)
58 {
59     SetName(rName);
60 }
61 
~ScAccessibleFilterMenuItem()62 ScAccessibleFilterMenuItem::~ScAccessibleFilterMenuItem()
63 {
64 }
65 
getAccessibleChildCount()66 sal_Int32 ScAccessibleFilterMenuItem::getAccessibleChildCount()
67     throw (RuntimeException)
68 {
69     return 0;
70 }
71 
getAccessibleChild(sal_Int32)72 Reference<XAccessible> ScAccessibleFilterMenuItem::getAccessibleChild(sal_Int32 /*nIndex*/)
73     throw (RuntimeException, IndexOutOfBoundsException)
74 {
75     throw IndexOutOfBoundsException();
76 }
77 
getAccessibleStateSet()78 Reference<XAccessibleStateSet> ScAccessibleFilterMenuItem::getAccessibleStateSet()
79     throw (RuntimeException)
80 {
81     updateStateSet();
82     return mxStateSet;
83 }
84 
getImplementationName()85 OUString ScAccessibleFilterMenuItem::getImplementationName()
86     throw (RuntimeException)
87 {
88     return OUString::createFromAscii("ScAccessibleFilterMenuItem");
89 }
90 
91 // XAccessibleAction
92 
getAccessibleActionCount()93 sal_Int32 ScAccessibleFilterMenuItem::getAccessibleActionCount() throw (RuntimeException)
94 {
95     return 1;
96 }
97 
doAccessibleAction(sal_Int32)98 sal_Bool ScAccessibleFilterMenuItem::doAccessibleAction(sal_Int32 /*nIndex*/)
99     throw (IndexOutOfBoundsException, RuntimeException)
100 {
101     mpWindow->executeMenuItem(mnMenuPos);
102     return true;
103 }
104 
getAccessibleActionDescription(sal_Int32)105 OUString ScAccessibleFilterMenuItem::getAccessibleActionDescription(sal_Int32 /*nIndex*/)
106     throw (IndexOutOfBoundsException, RuntimeException)
107 {
108     return OUString::createFromAscii("click");
109 }
110 
getAccessibleActionKeyBinding(sal_Int32)111 Reference<XAccessibleKeyBinding> ScAccessibleFilterMenuItem::getAccessibleActionKeyBinding(
112     sal_Int32 /*nIndex*/) throw (IndexOutOfBoundsException, RuntimeException)
113 {
114     return Reference<XAccessibleKeyBinding>();
115 }
116 
queryInterface(uno::Type const & rType)117 Any SAL_CALL ScAccessibleFilterMenuItem::queryInterface( uno::Type const & rType )
118 	throw (RuntimeException)
119 {
120 	Any any = ScAccessibleContextBase::queryInterface(rType);
121     if (any.hasValue())
122         return any;
123 
124     return ScAccessibleFilterMenuItem_BASE::queryInterface(rType);
125 }
126 
acquire()127 void SAL_CALL ScAccessibleFilterMenuItem::acquire() throw ()
128 {
129 	ScAccessibleContextBase::acquire();
130 }
131 
release()132 void SAL_CALL ScAccessibleFilterMenuItem::release() throw ()
133 {
134 	ScAccessibleContextBase::release();
135 }
136 
isSelected() const137 bool ScAccessibleFilterMenuItem::isSelected() const
138 {
139     return mpWindow->isMenuItemSelected(mnMenuPos);
140 }
141 
isFocused() const142 bool ScAccessibleFilterMenuItem::isFocused() const
143 {
144     return isSelected();
145 }
146 
setEnabled(bool bEnabled)147 void ScAccessibleFilterMenuItem::setEnabled(bool bEnabled)
148 {
149     mbEnabled = bEnabled;
150 }
151 
GetBoundingBoxOnScreen() const152 Rectangle ScAccessibleFilterMenuItem::GetBoundingBoxOnScreen() const
153     throw (RuntimeException)
154 {
155     if (!mpWindow->IsVisible())
156         return Rectangle();
157 
158     Point aPos = mpWindow->OutputToAbsoluteScreenPixel(Point(0,0));
159     Point aMenuPos;
160     Size aMenuSize;
161     mpWindow->getMenuItemPosSize(mnMenuPos, aMenuPos, aMenuSize);
162     Rectangle aRect(aPos + aMenuPos, aMenuSize);
163     return aRect;
164 }
165 
GetBoundingBox() const166 Rectangle ScAccessibleFilterMenuItem::GetBoundingBox() const
167     throw (RuntimeException)
168 {
169     if (!mpWindow->IsVisible())
170         return Rectangle();
171 
172     Point aMenuPos;
173     Size aMenuSize;
174     mpWindow->getMenuItemPosSize(mnMenuPos, aMenuPos, aMenuSize);
175     Rectangle aRect(aMenuPos, aMenuSize);
176     return aRect;
177 }
178 
updateStateSet()179 void ScAccessibleFilterMenuItem::updateStateSet()
180 {
181     if (!mxStateSet.is())
182         mxStateSet.set(new ScAccessibleStateSet);
183 
184     ScAccessibleStateSet* p = static_cast<ScAccessibleStateSet*>(
185         mxStateSet.get());
186 
187     p->clear();
188 
189     p->insert(ENABLED);
190     p->insert(FOCUSABLE);
191     p->insert(SELECTABLE);
192     p->insert(SENSITIVE);
193     p->insert(OPAQUE);
194 
195     if (isFocused())
196         p->insert(FOCUSED);
197 
198     if (isSelected())
199         p->insert(SELECTED);
200 }
201 
202