Line data Source code
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 <osl/mutex.hxx>
21 : #include <vcl/image.hxx>
22 : #include <vcl/menu.hxx>
23 :
24 : #include <cppuhelper/compbase4.hxx>
25 : #include <cppuhelper/compbase5.hxx>
26 : #include <comphelper/broadcasthelper.hxx>
27 :
28 : #include <com/sun/star/frame/XFrame.hpp>
29 : #include <com/sun/star/accessibility/XAccessible.hpp>
30 : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
32 : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
33 : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
34 : #include <com/sun/star/lang/DisposedException.hpp>
35 :
36 : #include <rtl/ref.hxx>
37 :
38 : #include <vector>
39 :
40 : #include <svtools/framestatuslistener.hxx>
41 :
42 : namespace svtools {
43 :
44 : struct ToolbarMenu_Impl;
45 : class ToolbarMenu;
46 : class ToolbarMenuEntry;
47 :
48 : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener > > EventListenerVector;
49 : typedef std::vector< ToolbarMenuEntry * > ToolbarMenuEntryVector;
50 :
51 : const int SEPARATOR_HEIGHT = 4;
52 : const int TITLE_ID = -1;
53 : const int BORDER_X = 0;
54 : const int BORDER_Y = 0;
55 :
56 :
57 : // - ToolbarMenuEntry -
58 :
59 :
60 : class ToolbarMenuEntry
61 : {
62 : public:
63 : ToolbarMenu& mrMenu;
64 :
65 : int mnEntryId;
66 : MenuItemBits mnBits;
67 : Size maSize;
68 :
69 : bool mbHasText;
70 : bool mbHasImage;
71 : bool mbChecked;
72 : bool mbEnabled;
73 :
74 : OUString maText;
75 : Image maImage;
76 : Control* mpControl;
77 : Rectangle maRect;
78 :
79 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > mxAccContext;
80 :
81 : public:
82 : ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const OUString& rText, MenuItemBits nBits );
83 : ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const Image& rImage, const OUString& rText, MenuItemBits nBits );
84 : ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, Control* pControl, MenuItemBits nBits );
85 : ~ToolbarMenuEntry();
86 :
87 : void init( int nEntryId, MenuItemBits nBits );
88 :
89 : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& GetAccessible( bool bCreate = false );
90 :
91 : sal_Int32 getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
92 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getAccessibleChild( sal_Int32 index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
93 : void selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
94 :
95 0 : bool HasCheck() const
96 : {
97 0 : return mbChecked || ( mnBits & ( MIB_RADIOCHECK | MIB_CHECKABLE | MIB_AUTOCHECK ) );
98 : }
99 : };
100 :
101 :
102 : // - ToolbarMenuAcc -
103 :
104 :
105 : typedef ::cppu::PartialWeakComponentImplHelper5<
106 : ::com::sun::star::accessibility::XAccessible,
107 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
108 : ::com::sun::star::accessibility::XAccessibleContext,
109 : ::com::sun::star::accessibility::XAccessibleComponent,
110 : ::com::sun::star::accessibility::XAccessibleSelection >
111 : ToolbarMenuAccComponentBase;
112 :
113 : class ToolbarMenuAcc :
114 : public ::comphelper::OBaseMutex,
115 : public ToolbarMenuAccComponentBase
116 : {
117 : public:
118 :
119 : ToolbarMenuAcc( ToolbarMenu_Impl& rParent );
120 : virtual ~ToolbarMenuAcc();
121 :
122 : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
123 0 : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
124 :
125 : public:
126 :
127 : // XComponent
128 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
129 0 : { WeakComponentImplHelperBase::dispose(); }
130 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
131 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
132 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
133 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
134 :
135 : // XAccessible
136 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
137 :
138 : // XAccessibleEventBroadcaster
139 : virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 : virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 :
142 : // XAccessibleContext
143 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
150 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 :
154 : // XAccessibleComponent
155 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
156 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
157 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
158 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
159 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
161 : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
162 : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
163 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
164 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 :
166 : // XAccessibleSelection
167 : virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
168 : virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 : virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
171 : virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
172 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 : virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
174 :
175 : DECL_LINK( WindowEventListener, VclSimpleEvent* );
176 :
177 : private:
178 : EventListenerVector mxEventListeners;
179 : ToolbarMenu_Impl* mpParent;
180 : /// The current FOCUSED state.
181 : bool mbIsFocused;
182 :
183 : void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent );
184 :
185 : /** Tell all listeners that the object is dying. This callback is
186 : usually called from the WeakComponentImplHelper class.
187 : */
188 : virtual void SAL_CALL disposing (void) SAL_OVERRIDE;
189 :
190 : /** Check whether or not the object has been disposed (or is in the
191 : state of beeing disposed). If that is the case then
192 : DisposedException is thrown to inform the (indirect) caller of the
193 : foul deed.
194 : */
195 : void ThrowIfDisposed (void) throw (::com::sun::star::lang::DisposedException);
196 : };
197 :
198 :
199 : // - ToolbarMenuEntryAcc -
200 :
201 :
202 : typedef ::cppu::PartialWeakComponentImplHelper4< ::com::sun::star::accessibility::XAccessible,
203 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
204 : ::com::sun::star::accessibility::XAccessibleContext,
205 : ::com::sun::star::accessibility::XAccessibleComponent > ToolbarMenuEntryAccBase;
206 :
207 : class ToolbarMenuEntryAcc : public ::comphelper::OBaseMutex,
208 : public ToolbarMenuEntryAccBase
209 : {
210 : public:
211 : ToolbarMenuEntryAcc( ToolbarMenuEntry* pParent );
212 : virtual ~ToolbarMenuEntryAcc();
213 :
214 : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
215 :
216 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
217 0 : { WeakComponentImplHelperBase::dispose(); }
218 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
219 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
220 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
221 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
222 :
223 : // XAccessible
224 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
225 :
226 : // XAccessibleEventBroadcaster
227 : virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
228 : virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
229 :
230 : // XAccessibleContext
231 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
232 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
233 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
234 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
235 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
236 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
237 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
238 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
239 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
240 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
241 :
242 : // XAccessibleComponent
243 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
244 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
245 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
246 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
247 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
248 : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
249 : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
250 : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
251 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
252 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
253 :
254 : private:
255 : EventListenerVector mxEventListeners;
256 : ::osl::Mutex maMutex;
257 : ToolbarMenuEntry* mpParent;
258 :
259 : /** Tell all listeners that the object is dying. This callback is
260 : usually called from the WeakComponentImplHelper class.
261 : */
262 : virtual void SAL_CALL disposing (void) SAL_OVERRIDE;
263 : };
264 :
265 :
266 :
267 : struct ToolbarMenu_Impl
268 : {
269 : ToolbarMenu& mrMenu;
270 :
271 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
272 : rtl::Reference< svt::FrameStatusListener > mxStatusListener;
273 : rtl::Reference< ToolbarMenuAcc > mxAccessible;
274 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > mxOldSelection;
275 :
276 : ToolbarMenuEntryVector maEntryVector;
277 :
278 : int mnCheckPos;
279 : int mnImagePos;
280 : int mnTextPos;
281 :
282 : int mnHighlightedEntry;
283 : int mnSelectedEntry;
284 : int mnLastColumn;
285 :
286 : Size maSize;
287 :
288 : Link maSelectHdl;
289 :
290 : ToolbarMenu_Impl( ToolbarMenu& rMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame );
291 : ~ToolbarMenu_Impl();
292 :
293 : void setAccessible( ToolbarMenuAcc* pAccessible );
294 :
295 : void fireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
296 : bool hasAccessibleListeners();
297 :
298 : sal_Int32 getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
299 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getAccessibleChild( sal_Int32 index ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
300 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getAccessibleChild( Control* pControl, sal_Int32 childIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
301 :
302 : void selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
303 : sal_Bool isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
304 : void clearAccessibleSelection();
305 :
306 : ToolbarMenuEntry* implGetEntry( int nEntry ) const;
307 : void notifyHighlightedEntry();
308 :
309 : void implHighlightControl( sal_uInt16 nCode, Control* pControl );
310 : };
311 :
312 : }
313 :
314 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|