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