Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <osl/mutex.hxx>
30 : : #include <vcl/image.hxx>
31 : : #include <vcl/menu.hxx>
32 : :
33 : : #include <cppuhelper/compbase4.hxx>
34 : : #include <cppuhelper/compbase5.hxx>
35 : : #include <comphelper/broadcasthelper.hxx>
36 : :
37 : : #include <com/sun/star/frame/XFrame.hpp>
38 : : #include <com/sun/star/accessibility/XAccessible.hpp>
39 : : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
40 : : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
41 : : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
42 : : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
43 : : #include <com/sun/star/lang/DisposedException.hpp>
44 : :
45 : : #include <rtl/ref.hxx>
46 : :
47 : : #include <vector>
48 : :
49 : : #include "framestatuslistener.hxx"
50 : :
51 : : namespace svtools {
52 : :
53 : : struct ToolbarMenu_Impl;
54 : : class ToolbarMenu;
55 : : class ToolbarMenuEntry;
56 : :
57 : : typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener > > EventListenerVector;
58 : : typedef std::vector< ToolbarMenuEntry * > ToolbarMenuEntryVector;
59 : :
60 : : const int SEPARATOR_HEIGHT = 4;
61 : : const int TITLE_ID = -1;
62 : : const int BORDER_X = 0;
63 : : const int BORDER_Y = 0;
64 : :
65 : : // --------------------
66 : : // - ToolbarMenuEntry -
67 : : // --------------------
68 : :
69 : : class ToolbarMenuEntry
70 : : {
71 : : public:
72 : : ToolbarMenu& mrMenu;
73 : :
74 : : int mnEntryId;
75 : : MenuItemBits mnBits;
76 : : Size maSize;
77 : :
78 : : bool mbHasText;
79 : : bool mbHasImage;
80 : : bool mbChecked;
81 : : bool mbEnabled;
82 : :
83 : : String maText;
84 : : Image maImage;
85 : : Control* mpControl;
86 : : Rectangle maRect;
87 : :
88 : : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > mxAccContext;
89 : :
90 : : public:
91 : : ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const String& rText, MenuItemBits nBits );
92 : : ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, const Image& rImage, const String& rText, MenuItemBits nBits );
93 : : ToolbarMenuEntry( ToolbarMenu& rMenu, int nEntryId, Control* pControl, MenuItemBits nBits );
94 : : ~ToolbarMenuEntry();
95 : :
96 : : void init( int nEntryId, MenuItemBits nBits );
97 : :
98 : : const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext >& GetAccessible( bool bCreate = false );
99 : :
100 : : sal_Int32 getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
101 : : ::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);
102 : : void selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
103 : :
104 : 0 : bool HasCheck() const
105 : : {
106 [ # # ][ # # ]: 0 : return mbChecked || ( mnBits & ( MIB_RADIOCHECK | MIB_CHECKABLE | MIB_AUTOCHECK ) );
107 : : }
108 : : };
109 : :
110 : : // ---------------
111 : : // - ToolbarMenuAcc -
112 : : // ---------------
113 : :
114 : : typedef ::cppu::PartialWeakComponentImplHelper5<
115 : : ::com::sun::star::accessibility::XAccessible,
116 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
117 : : ::com::sun::star::accessibility::XAccessibleContext,
118 : : ::com::sun::star::accessibility::XAccessibleComponent,
119 : : ::com::sun::star::accessibility::XAccessibleSelection >
120 : : ToolbarMenuAccComponentBase;
121 : :
122 : : class ToolbarMenuAcc :
123 : : public ::comphelper::OBaseMutex,
124 : : public ToolbarMenuAccComponentBase
125 : : {
126 : : public:
127 : :
128 : : ToolbarMenuAcc( ToolbarMenu_Impl& rParent );
129 : : ~ToolbarMenuAcc();
130 : :
131 : : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
132 : 0 : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
133 : :
134 : : public:
135 : :
136 : : // XComponent
137 : 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException)
138 : 0 : { WeakComponentImplHelperBase::dispose(); }
139 : 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
140 : 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
141 : 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
142 : 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
143 : :
144 : : // XAccessible
145 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException);
146 : :
147 : : // XAccessibleEventBroadcaster
148 : : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
149 : : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
150 : :
151 : : // XAccessibleContext
152 : : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException);
153 : : 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);
154 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException);
155 : : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException);
156 : : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException);
157 : : virtual ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException);
158 : : virtual ::rtl::OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException);
159 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException);
160 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException);
161 : : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
162 : :
163 : : // XAccessibleComponent
164 : : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
165 : : 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);
166 : : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException);
167 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException);
168 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException);
169 : : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException);
170 : : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException);
171 : : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
172 : : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
173 : : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
174 : :
175 : : // XAccessibleSelection
176 : : virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
177 : : virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
178 : : virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException);
179 : : virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException);
180 : : virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException);
181 : : 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);
182 : : virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
183 : :
184 : : DECL_LINK( WindowEventListener, VclSimpleEvent* );
185 : :
186 : : private:
187 : : EventListenerVector mxEventListeners;
188 : : ToolbarMenu_Impl* mpParent;
189 : : /// The current FOCUSED state.
190 : : bool mbIsFocused;
191 : :
192 : : void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent );
193 : :
194 : : /** Tell all listeners that the object is dying. This callback is
195 : : usually called from the WeakComponentImplHelper class.
196 : : */
197 : : virtual void SAL_CALL disposing (void);
198 : :
199 : : /** Check whether or not the object has been disposed (or is in the
200 : : state of beeing disposed). If that is the case then
201 : : DisposedException is thrown to inform the (indirect) caller of the
202 : : foul deed.
203 : : */
204 : : void ThrowIfDisposed (void) throw (::com::sun::star::lang::DisposedException);
205 : : };
206 : :
207 : : // -----------------------
208 : : // - ToolbarMenuEntryAcc -
209 : : // -----------------------
210 : :
211 : : typedef ::cppu::PartialWeakComponentImplHelper4< ::com::sun::star::accessibility::XAccessible,
212 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
213 : : ::com::sun::star::accessibility::XAccessibleContext,
214 : : ::com::sun::star::accessibility::XAccessibleComponent > ToolbarMenuEntryAccBase;
215 : :
216 : : class ToolbarMenuEntryAcc : public ::comphelper::OBaseMutex,
217 : : public ToolbarMenuEntryAccBase
218 : : {
219 : : public:
220 : : ToolbarMenuEntryAcc( ToolbarMenuEntry* pParent );
221 : : ~ToolbarMenuEntryAcc();
222 : :
223 : : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
224 : :
225 : 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException)
226 : 0 : { WeakComponentImplHelperBase::dispose(); }
227 : 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
228 : 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
229 : 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
230 : 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
231 : :
232 : : // XAccessible
233 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException);
234 : :
235 : : // XAccessibleEventBroadcaster
236 : : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
237 : : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
238 : :
239 : : // XAccessibleContext
240 : : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException);
241 : : 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);
242 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException);
243 : : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException);
244 : : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException);
245 : : virtual ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException);
246 : : virtual ::rtl::OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException);
247 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException);
248 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException);
249 : : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
250 : :
251 : : // XAccessibleComponent
252 : : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
253 : : 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);
254 : : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException);
255 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException);
256 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException);
257 : : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException);
258 : : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException);
259 : : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
260 : : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
261 : : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
262 : :
263 : : private:
264 : : EventListenerVector mxEventListeners;
265 : : ::osl::Mutex maMutex;
266 : : ToolbarMenuEntry* mpParent;
267 : :
268 : : /** Tell all listeners that the object is dying. This callback is
269 : : usually called from the WeakComponentImplHelper class.
270 : : */
271 : : virtual void SAL_CALL disposing (void);
272 : : };
273 : :
274 : : // -----------------------------------------------------------------------------
275 : :
276 : : struct ToolbarMenu_Impl
277 : : {
278 : : ToolbarMenu& mrMenu;
279 : :
280 : : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
281 : : rtl::Reference< svt::FrameStatusListener > mxStatusListener;
282 : : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxServiceManager;
283 : : rtl::Reference< ToolbarMenuAcc > mxAccessible;
284 : : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > mxOldSelection;
285 : :
286 : : ToolbarMenuEntryVector maEntryVector;
287 : :
288 : : int mnCheckPos;
289 : : int mnImagePos;
290 : : int mnTextPos;
291 : :
292 : : int mnHighlightedEntry;
293 : : int mnSelectedEntry;
294 : : int mnLastColumn;
295 : :
296 : : Size maSize;
297 : :
298 : : Link maSelectHdl;
299 : :
300 : : ToolbarMenu_Impl( ToolbarMenu& rMenu, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame );
301 : : ~ToolbarMenu_Impl();
302 : :
303 : : void setAccessible( ToolbarMenuAcc* pAccessible );
304 : :
305 : : void fireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
306 : : bool hasAccessibleListeners();
307 : :
308 : : sal_Int32 getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException);
309 : : ::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);
310 : : ::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);
311 : :
312 : : void selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
313 : : sal_Bool isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
314 : : void clearAccessibleSelection();
315 : :
316 : : ToolbarMenuEntry* implGetEntry( int nEntry ) const;
317 : : void notifyHighlightedEntry();
318 : :
319 : : void implHighlightControl( sal_uInt16 nCode, Control* pControl );
320 : : };
321 : :
322 : : }
323 : :
324 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|